Feature #14370


Directly mark instruction operands and avoid mark_ary usage on rb_iseq_constant_body

Added by tenderlovemaking (Aaron Patterson) over 3 years ago. Updated over 3 years ago.

Target version:



I've attached a patch that changes rb_iseq_mark to directly mark instruction operands rather than adding them to a mark array. I observed a ~3% memory reduction by directly marking operands, and I didn't observe any difference in GC time. To test memory usage, I used a basic Rails application, logged all malloc / free calls to a file, then wrote a script that would sum the live memory at each sample (each sample being a call to malloc). I graphed these totals so that I could see the memory usage as malloc calls were made:

memory usage graph

The red line is trunk, the blue line is trunk + the patch I've attached. Since the X axis is sample number (not time), the blue line is not as long as the red line because the blue line calls malloc fewer times. The Y axis in the graph is the total number of "live" bytes that have been allocated (all allocations minus their corresponding frees). You can see from the graph that memory savings start adding up as more code gets loaded.

I was concerned that this patch might impact GC time, but make gcbench-rdoc didn't seem to show any significant difference in GC time between trunk and this patch. If it turns out there is a performance impact, I think I could improve the time while still keeping memory usage low by generating a bitmap during iseq compilation.

There is a bit more information where I've been working, but I think I've summarized everything here.


iseq_mark.diff (6.28 KB) iseq_mark.diff tenderlovemaking (Aaron Patterson), 01/17/2018 08:11 PM
iseq_mark.diff (6.28 KB) iseq_mark.diff Update iseq mark function v2 tenderlovemaking (Aaron Patterson), 01/18/2018 06:53 PM
iseq_mark.diff (7.26 KB) iseq_mark.diff Mark instructions v3 tenderlovemaking (Aaron Patterson), 01/20/2018 02:49 AM
benchmark_methods.diff (1.23 KB) benchmark_methods.diff Methods used in benchmark tenderlovemaking (Aaron Patterson), 01/20/2018 02:50 AM
bench.rb (3.01 KB) bench.rb Benchmark for iseq scanning tenderlovemaking (Aaron Patterson), 01/20/2018 02:50 AM
direct_marking.diff (18.4 KB) direct_marking.diff direct marking, removing mark array tenderlovemaking (Aaron Patterson), 02/06/2018 12:32 AM

Related issues

Related to Ruby master - Bug #14596: Ruby master is broken with bootsnapClosedActions

Also available in: Atom PDF