Issue #19315 has been updated by himura467 (Akito Shitara). Also, I ran ruby-bench on arm64-darwin25 (warmup=3, bench=10). **Standard harness** (72 benchmarks, geomean current/master = 0.998): | bench | current (ms) | master (ms) | current/master | | -------------------- | ------------- | ------------- | -------------- | | psych-load | 1280.7 ± 0.8% | 1244.0 ± 0.2% | 1.029 | | sequel | 32.2 ± 4.7% | 31.4 ± 4.5% | 1.027 | | protoboeuf | 104.4 ± 0.1% | 103.0 ± 0.7% | 1.014 | | ... | ... | ... | ... | | addressable-equality | 348.6 ± 1.2% | 356.8 ± 0.5% | 0.977 | | ruby-lsp | 94.8 ± 3.3% | 99.0 ± 2.8% | 0.958 | | fluentd | 237.3 ± 1.9% | 262.2 ± 1.9% | 0.905 | **Ractor harness** (30 benchmarks, geomean current/master = 0.993): Note: results with large RSD should be treated with caution. | bench | current (ms) | master (ms) | current/master | | --------------------- | ------------- | ------------- | -------------- | | setivar_young | 216000 ± 333% | 205667 ± 321% | 1.050 | | getivar-module | 310400 ± 26% | 303467 ± 26% | 1.023 | | object-new-initialize | 136800 ± 59% | 134567 ± 59% | 1.017 | | ... | ... | ... | ... | | fannkuchredux | 414967 ± 18% | 432167 ± 28% | 0.960 | | gvl_release_acquire | 399167 ± 103% | 442867 ± 104% | 0.901 | | graphql | 58733 ± 44% | 66833 ± 61% | 0.879 | It appears no regression is observed in either harness. Note that ruby-bench does not include middle-substring heavy workloads; the speedup from `SHARABLE_MIDDLE_SUBSTRING` is shown in the previous comment. ---------------------------------------- Feature #19315: Lazy substrings in CRuby https://bugs.ruby-lang.org/issues/19315#change-117814 * Author: Eregon (Benoit Daloze) * Status: Open ---------------------------------------- CRuby should implement lazy substrings, i.e., "abcdef"[1..3] must not copy bytes. Currently CRuby only reuse the char* if the substring is until the end of the buffer. But it should also work wherever the substring starts and ends. Yes, it means RSTRING_PTR() might need to allocate to \0-terminate, so be it, it's worth it. There is already code for this (`SHARABLE_MIDDLE_SUBSTRING`), but it's disabled by default and `RSTRING_PTR()` needs to be changed to deal with this. It seems a good idea to introduce a variant of `RSTRING_PTR` which doesn't guarantee \0-termination, so such callers can then use the existing bytes always without copy. There are countless workarounds for this missing optimization, all not worth it with lazy substring and all less readable: * https://bugs.ruby-lang.org/issues/19314 * https://bugs.ruby-lang.org/issues/18598#note-3 * https://github.com/ruby/net-protocol/pull/14 * Manual lazy substrings which track string + index + length * More but I don't remember all now, feel free to comment or link more urls/tickets. -- https://bugs.ruby-lang.org/