From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A4E25203BB; Tue, 30 Jun 2015 20:11:02 +0000 (UTC) Date: Tue, 30 Jun 2015 20:11:02 +0000 From: Eric Wong To: spew@80x24.org Subject: Re: [PATCH] struct.c: speedup for big structs Message-ID: <20150630201102.GA14164@dcvr.yhbt.net> References: <1435011362-18488-1-git-send-email-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1435011362-18488-1-git-send-email-e@80x24.org> List-Id: Eric Wong wrote: > use simple custom open-addressing hash for big structs. > > Thanks to Sokolov Yura aka funny_falcon > in https://bugs.ruby-lang.org/issues/10585 Will squash the following when I commit. Freezing __members__ is necessary, but RB_GC_GUARD isn't needed since __members__ already becomes an ivar. diff --git a/struct.c b/struct.c index fbde80d..eda5673 100644 --- a/struct.c +++ b/struct.c @@ -84,12 +84,13 @@ struct_member_pos_probe(long prev, long mask) return (prev * 5 + 2) & mask; } -static void +static VALUE struct_set_members(VALUE klass, VALUE members) { VALUE back; members = rb_ary_dup(members); + rb_obj_freeze(members); if (RARRAY_LEN(members) <= AREF_HASH_THRESHOLD) { back = members; @@ -121,7 +122,8 @@ struct_set_members(VALUE klass, VALUE members) rb_obj_freeze(back); rb_ivar_set(klass, id_members, members); rb_ivar_set(klass, id_back_members, back); - RB_GC_GUARD(members); + + return members; } static inline int @@ -305,8 +307,7 @@ setup_struct(VALUE nstr, VALUE members) const VALUE *ptr_members; long i, len; - OBJ_FREEZE(members); - struct_set_members(nstr, members); + members = struct_set_members(nstr, members); rb_define_alloc_func(nstr, struct_alloc); rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1);