Skip to content

Make RBS::Location write-barrier protected (backport to 4.0.x)#3024

Open
soutaro wants to merge 1 commit into
aaa-4.0.xfrom
claude/location-minor-gc-skip-4.0.x
Open

Make RBS::Location write-barrier protected (backport to 4.0.x)#3024
soutaro wants to merge 1 commit into
aaa-4.0.xfrom
claude/location-minor-gc-skip-4.0.x

Conversation

@soutaro

@soutaro soutaro commented Jul 9, 2026

Copy link
Copy Markdown
Member

Backport of #3022 to the aaa-4.0.x branch.

Summary

Marks the RBS::Location TypedData object with RUBY_TYPED_WB_PROTECTED and routes every write to the embedded buffer VALUE through RB_OBJ_WRITE. Once an object is write-barrier protected, the GC can skip it during minor collections instead of marking it on every cycle, which speeds up GC.

Details

All buffer assignments now go through the write barrier so the old-to-young reference from a promoted Location to its Buffer is tracked correctly:

  • location_initialize
  • location_initialize_copy
  • rbs_new_location
  • rbs_new_location2
  • rbs_new_location_from_loc_range

Verification

  • Extension compiles cleanly on aaa-4.0.x.
  • ObjectSpace.dump reports "wb_protected": true for a Location, confirming it becomes skippable in minor GC.
  • GC.verify_internal_consistency passes at every stage of a stress test that promotes Locations to the old generation and churns the young generation across minor GCs; referenced Buffers stay intact.
  • The dup (initialize_copy) path holds up under GC.stress = true.
  • test/rbs/location_test.rb passes (11 tests, 115 assertions).

🤖 Generated with Claude Code

https://claude.ai/code/session_011JK4Acfc1aTzpgpPZxwJLF


Generated by Claude Code

Mark the Location TypedData object with RUBY_TYPED_WB_PROTECTED and route
every write to the embedded `buffer` VALUE through RB_OBJ_WRITE. Once an
object is write-barrier protected, the GC can skip it during minor
collections instead of marking it every time, which speeds up GC.

All buffer assignments (initialize, initialize_copy, and the three
rbs_new_location* constructors) now go through the write barrier so the
old-to-young reference from a promoted Location to its Buffer is tracked
correctly.
@soutaro soutaro added this to the RBS 4.0.x milestone Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants