8993cb5a3c (master): Make `remove_unreachable_chunk` linear in method size (#18823)

0 views
Skip to first unread message

Hiroya Fujinami

unread,
3:11 AM (14 hours ago) 3:11 AM
to ruby...@g.ruby-lang.org
Hiroya Fujinami 2026-10-06 07:10:52 +0000 (Tue, 06 Oct 2026)

New Revision: 8993cb5a3c

https://github.com/ruby/ruby/commit/8993cb5a3c

Log:
Make `remove_unreachable_chunk` linear in method size (#18823)

* Make remove_unreachable_chunk linear in method size

remove_unreachable_chunk allocated and cleared a label_no-sized
counter array on every call, and iseq_peephole_optimize calls it for
every unconditional jump and leave, so compiling a method cost
O(jumps * labels): quadratic in the size of the method.

Keep one scratch table in iseq_compile_data and stamp each entry with
a generation, so a new call invalidates the table by bumping the
generation instead of clearing it. The arrays live in the compile
arena and grow by doubling; a stamp wrap-around falls back to one
full clear. This also removes an unbounded ALLOCA_N sized by
label_no.

The compiled output is unchanged: the reproducer corpus compiles to
byte-identical iseq binaries, and the reproducer drops from 3.6 s to
0.13 s.

[Bug #22313]

* Make unreachable_unref fields local struct

https://github.com/ruby/ruby/pull/18823#issuecomment-5769711739

* Use ALLOCV_N instead of VLA

* Add a test case

* Remove the test case previously added

Modified files:
compile.c
Reply all
Reply to author
Forward
0 new messages