ruby-changes:62506
From: Kazuki <ko1@a...>
Date: Sun, 2 Aug 2020 01:07:24 +0900 (JST)
Subject: [ruby-changes:62506] fcdbdff631 (master): rb_{ary, fnd}_pattern_info: Remove imemo member to reduce memory usage
https://git.ruby-lang.org/ruby.git/commit/?id=fcdbdff631 From fcdbdff631a1a6bcc2229d448ed7c76041fe3258 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto <kazuki@c...> Date: Sun, 2 Aug 2020 01:03:43 +0900 Subject: rb_{ary,fnd}_pattern_info: Remove imemo member to reduce memory usage This is a partial revert commit of 8f096226e1b76f95f4d853d3dea2bc75eeeb5244. NODE layout: Before: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | pconst | pconst | pconst u2 | unused | unused | pkwargs u3 | apinfo | fpinfo | pkwrestarg After: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | imemo | imemo | pkwargs u2 | pconst | pconst | pconst u3 | apinfo | fpinfo | pkwrestarg diff --git a/node.c b/node.c index 01ec4be..7c291a8 100644 --- a/node.c +++ b/node.c @@ -1294,18 +1294,6 @@ static void https://github.com/ruby/ruby/blob/trunk/node.c#L1294 mark_ast_value(void *ctx, NODE * node) { switch (nd_type(node)) { - case NODE_ARYPTN: - { - struct rb_ary_pattern_info *apinfo = node->nd_apinfo; - rb_gc_mark_movable(apinfo->imemo); - break; - } - case NODE_FNDPTN: - { - struct rb_fnd_pattern_info *fpinfo = node->nd_fpinfo; - rb_gc_mark_movable(fpinfo->imemo); - break; - } case NODE_ARGS: { struct rb_args_info *args = node->nd_ainfo; @@ -1320,6 +1308,8 @@ mark_ast_value(void *ctx, NODE * node) https://github.com/ruby/ruby/blob/trunk/node.c#L1308 case NODE_DXSTR: case NODE_DREGX: case NODE_DSYM: + case NODE_ARYPTN: + case NODE_FNDPTN: rb_gc_mark_movable(node->nd_lit); break; default: @@ -1331,18 +1321,6 @@ static void https://github.com/ruby/ruby/blob/trunk/node.c#L1321 update_ast_value(void *ctx, NODE * node) { switch (nd_type(node)) { - case NODE_ARYPTN: - { - struct rb_ary_pattern_info *apinfo = node->nd_apinfo; - apinfo->imemo = rb_gc_location(apinfo->imemo); - break; - } - case NODE_FNDPTN: - { - struct rb_fnd_pattern_info *fpinfo = node->nd_fpinfo; - fpinfo->imemo = rb_gc_location(fpinfo->imemo); - break; - } case NODE_ARGS: { struct rb_args_info *args = node->nd_ainfo; @@ -1357,6 +1335,8 @@ update_ast_value(void *ctx, NODE * node) https://github.com/ruby/ruby/blob/trunk/node.c#L1335 case NODE_DXSTR: case NODE_DREGX: case NODE_DSYM: + case NODE_ARYPTN: + case NODE_FNDPTN: node->nd_lit = rb_gc_location(node->nd_lit); break; default: diff --git a/node.h b/node.h index 8252955..b6fefb4 100644 --- a/node.h +++ b/node.h @@ -273,8 +273,8 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L273 #define nd_brace u2.argc -#define nd_pconst u1.node -#define nd_pkwargs u2.node +#define nd_pkwargs u1.node +#define nd_pconst u2.node #define nd_pkwrestarg u3.node #define nd_apinfo u3.apinfo @@ -458,14 +458,12 @@ struct rb_ary_pattern_info { https://github.com/ruby/ruby/blob/trunk/node.h#L458 NODE *pre_args; NODE *rest_arg; NODE *post_args; - VALUE imemo; }; struct rb_fnd_pattern_info { NODE *pre_rest_arg; NODE *args; NODE *post_rest_arg; - VALUE imemo; }; struct parser_params; diff --git a/parse.y b/parse.y index b29e719..ba10c55 100644 --- a/parse.y +++ b/parse.y @@ -829,12 +829,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/parse.y#L829 new_array_pattern(struct parser_params *p, VALUE constant, VALUE pre_arg, VALUE aryptn, const YYLTYPE *loc) { NODE *t = (NODE *)aryptn; - struct rb_ary_pattern_info *apinfo = t->nd_apinfo; - VALUE pre_args, rest_arg, post_args; - - pre_args = rb_ary_entry(apinfo->imemo, 0); - rest_arg = rb_ary_entry(apinfo->imemo, 1); - post_args = rb_ary_entry(apinfo->imemo, 2); + VALUE pre_args = t->u1.value, rest_arg = t->u2.value, post_args = t->u3.value; if (!NIL_P(pre_arg)) { if (!NIL_P(pre_args)) { @@ -851,7 +846,6 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/parse.y#L846 new_array_pattern_tail(struct parser_params *p, VALUE pre_args, VALUE has_rest, VALUE rest_arg, VALUE post_args, const YYLTYPE *loc) { NODE *t; - struct rb_ary_pattern_info *apinfo; if (has_rest) { rest_arg = dispatch1(var_field, rest_arg ? rest_arg : Qnil); @@ -860,14 +854,10 @@ new_array_pattern_tail(struct parser_params *p, VALUE pre_args, VALUE has_rest, https://github.com/ruby/ruby/blob/trunk/parse.y#L854 rest_arg = Qnil; } - VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer(); - apinfo = ZALLOC(struct rb_ary_pattern_info); - rb_imemo_tmpbuf_set_ptr(tmpbuf, apinfo); - apinfo->imemo = rb_ary_new_from_args(4, pre_args, rest_arg, post_args, tmpbuf); - - t = rb_node_newnode(NODE_ARYPTN, Qnil, Qnil, (VALUE)apinfo, &NULL_LOC); - RB_OBJ_WRITTEN(p->ast, Qnil, apinfo->imemo); - + t = rb_node_newnode(NODE_ARYPTN, pre_args, rest_arg, post_args, &NULL_LOC); + add_mark_object(p, pre_args); + add_mark_object(p, rest_arg); + add_mark_object(p, post_args); return (VALUE)t; } @@ -875,12 +865,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/parse.y#L865 new_find_pattern(struct parser_params *p, VALUE constant, VALUE fndptn, const YYLTYPE *loc) { NODE *t = (NODE *)fndptn; - struct rb_fnd_pattern_info *fpinfo = t->nd_fpinfo; - VALUE pre_rest_arg, args, post_rest_arg; - - pre_rest_arg = rb_ary_entry(fpinfo->imemo, 0); - args = rb_ary_entry(fpinfo->imemo, 1); - post_rest_arg = rb_ary_entry(fpinfo->imemo, 2); + VALUE pre_rest_arg = t->u1.value, args = t->u2.value, post_rest_arg = t->u3.value; return dispatch4(fndptn, constant, pre_rest_arg, args, post_rest_arg); } @@ -889,19 +874,14 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/parse.y#L874 new_find_pattern_tail(struct parser_params *p, VALUE pre_rest_arg, VALUE args, VALUE post_rest_arg, const YYLTYPE *loc) { NODE *t; - struct rb_fnd_pattern_info *fpinfo; pre_rest_arg = dispatch1(var_field, pre_rest_arg ? pre_rest_arg : Qnil); post_rest_arg = dispatch1(var_field, post_rest_arg ? post_rest_arg : Qnil); - VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer(); - fpinfo = ZALLOC(struct rb_fnd_pattern_info); - rb_imemo_tmpbuf_set_ptr(tmpbuf, fpinfo); - fpinfo->imemo = rb_ary_new_from_args(4, pre_rest_arg, args, post_rest_arg, tmpbuf); - - t = rb_node_newnode(NODE_FNDPTN, Qnil, Qnil, (VALUE)fpinfo, &NULL_LOC); - RB_OBJ_WRITTEN(p->ast, Qnil, fpinfo->imemo); - + t = rb_node_newnode(NODE_FNDPTN, pre_rest_arg, args, post_rest_arg, &NULL_LOC); + add_mark_object(p, pre_rest_arg); + add_mark_object(p, args); + add_mark_object(p, post_rest_arg); return (VALUE)t; } @@ -11602,8 +11582,7 @@ new_array_pattern_tail(struct parser_params *p, NODE *pre_args, int has_rest, ID https://github.com/ruby/ruby/blob/trunk/parse.y#L11582 VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer(); struct rb_ary_pattern_info *apinfo = ZALLOC(struct rb_ary_pattern_info); rb_imemo_tmpbuf_set_ptr(tmpbuf, apinfo); - node = NEW_NODE(NODE_ARYPTN, 0, 0, apinfo, loc); - apinfo->imemo = tmpbuf; + node = NEW_NODE(NODE_ARYPTN, tmpbuf, 0, apinfo, loc); RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf); apinfo->pre_args = pre_args; @@ -11642,8 +11621,7 @@ new_find_pattern_tail(struct parser_params *p, ID pre_rest_arg, NODE *args, ID p https://github.com/ruby/ruby/blob/trunk/parse.y#L11621 VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer(); struct rb_fnd_pattern_info *fpinfo = ZALLOC(struct rb_fnd_pattern_info); rb_imemo_tmpbuf_set_ptr(tmpbuf, fpinfo); - node = NEW_NODE(NODE_FNDPTN, 0, 0, fpinfo, loc); - fpinfo->imemo = tmpbuf; + node = NEW_NODE(NODE_FNDPTN, tmpbuf, 0, fpinfo, loc); RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf); fpinfo->pre_rest_arg = pre_rest_arg ? assignable(p, pre_rest_arg, 0, loc) : NODE_SPECIAL_NO_NAME_REST; @@ -11677,7 +11655,7 @@ new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, co https://github.com/ruby/ruby/blob/trunk/parse.y#L11655 kw_rest_arg_node = NULL; } - node = NEW_NODE(NODE_HSHPTN, 0, kw_args, kw_rest_arg_node, loc); + node = NEW_NODE(NODE_HSHPTN, kw_args, 0, kw_rest_arg_node, loc); p->ruby_sourceline = saved_line; return node; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/