Issue #19315 has been updated by himura467 (Akito Shitara). File output_001.txt added [Feature #22186] landed as commit:https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/a90..., so per Matz's request in #22186#note-16 I am revisiting this. ruby-bench with `SHARABLE_MIDDLE_SUBSTRING` enabled on top of post-#22186 master. arm64-darwin25, 75 benchmarks, warmup 15, bench 15: geomean master/current, time = 1.0011 geomean master/current, RSS = 0.9968 `fluentd` is 1.021 (±1.9%), which looks consistent with #note-54: the improvement in #note-52 appears to have belonged to #22186. The O(n) to O(1) benefit of #note-50 only begins above ~1024 bytes, and ruby-bench takes no middle substrings that large, which is why both time and RSS are flat. The application-level evaluation mame asked for in #note-43 is also still missing. How about moving the design of "how to represent a String whose buffer is not NUL-terminated" to [Feature #22056]? I have written up a proposal there. ---------------------------------------- Feature #19315: Lazy substrings in CRuby https://bugs.ruby-lang.org/issues/19315#change-118612 * 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. ---Files-------------------------------- ruby-bench-ratio.png (230 KB) output_001.txt (12.8 KB) -- https://bugs.ruby-lang.org/