Skip to content

[PoC] Lazy substrings: add RSTRING_START(), enable SHARABLE_MIDDLE_SUBSTRING - #17045

Closed
himura467 wants to merge 16 commits into
ruby:masterfrom
himura467:lazy-substrings-rstring-start
Closed

himura467 wants to merge 16 commits into
ruby:masterfrom
himura467:lazy-substrings-rstring-start

Conversation

@himura467

Copy link
Copy Markdown
Contributor

Summary

This is a PoC for enabling SHARABLE_MIDDLE_SUBSTRING=1 (proposed in https://bugs.ruby-lang.org/issues/19315), which allows zero-copy shared substrings for arbitrary ranges (not just tail ranges).

The key challenge is that a shared middle substring may not have a null terminator at ptr[len], so RSTRING_PTR() must lazily ensure termination before returning the pointer. This PoC implements that guarantee.

Thinking

RSTRING_GETMEM internally calls RSTRING_PTR(), so callers that only need the pointer+length (no null termination) also pay the overhead. A RSTRING_GETMEM_START variant could be added to allow gradual migration of internal callers, while keeping RSTRING_GETMEM for backward compatibility with C extensions.

Testing

Existing tests pass without modification. No new test cases are added in this PoC; proper coverage for middle-shared substrings and multi-byte terminators should be added before merging.

@himura467
himura467 force-pushed the lazy-substrings-rstring-start branch 3 times, most recently from 853f0a7 to 2c8ec8d Compare May 20, 2026 18:37
Comment thread string.c Outdated
Comment thread string.c Outdated
Comment thread include/ruby/internal/core/rstring.h Outdated
Comment thread string.c Outdated
@himura467
himura467 force-pushed the lazy-substrings-rstring-start branch 2 times, most recently from 2f9b7f6 to bfd6076 Compare May 28, 2026 19:17
Comment thread string.c
Comment thread include/ruby/internal/core/rstring.h Outdated
@himura467
himura467 force-pushed the lazy-substrings-rstring-start branch 2 times, most recently from 03a9bc6 to 678ac7f Compare June 1, 2026 06:38
@himura467
himura467 force-pushed the lazy-substrings-rstring-start branch 2 times, most recently from 56663bf to b8b60f0 Compare June 21, 2026 06:41
@himura467
himura467 force-pushed the lazy-substrings-rstring-start branch from b8b60f0 to 5a66cb9 Compare June 21, 2026 06:43
@himura467 himura467 closed this Sep 15, 2026
@himura467
himura467 deleted the lazy-substrings-rstring-start branch September 15, 2026 13:47
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