Issue #19315 has been updated by mame (Yusuke Endoh). File ruby-bench-ratio.png added Thanks for running the benchmarks. I made a chart to visualize the results.  The further left a bar is, the faster your change is than master; the further right, the slower. Looking at the results, fluentd is the one case with a clear improvement. (ruby-lsp looks large, but the error bars are wide so I'm less confident about it.) A few others show small gains too, but most are a mixed bag, faster in some places and slower in others, so overall they come out about even. That makes the decision tricky. Since most workloads don't show a clear win, it's hard to say whether the gain justifies the compatibility risk. ---------------------------------------- Feature #19315: Lazy substrings in CRuby https://bugs.ruby-lang.org/issues/19315#change-117832 * 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) -- https://bugs.ruby-lang.org/