Skip to content

[runtime] Avoid intermediate copy in FlatString::substring - #503

Merged
Hans-Halverson merged 1 commit into
masterfrom
faster-substring
Aug 12, 2026
Merged

[runtime] Avoid intermediate copy in FlatString::substring#503
Hans-Halverson merged 1 commit into
masterfrom
faster-substring

Conversation

@Hans-Halverson

@Hans-Halverson Hans-Halverson commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

Easy win: FlatString::substring was first copying the substring to a temporary Vec, allocating the new string, and then copying the contents into the new string. Avoid this unnecessary intermediate copy by allocating an uninitialized FlatString (with a new canonical creation utility) and then copying the bytes over directly.

Notes:

  • Also return the original string directly if the substring is just the full string (which can be common for RegExp matches)
  • Do the same for FlatString::substring_by_byte_index

+8.8% improvement to Octane RegExp benchmark from this change, and ~+0.8% overall increase to Octane score.

Tests

  • CI

@Hans-Halverson
Hans-Halverson merged commit 3ce5f60 into master Aug 12, 2026
11 checks passed
@Hans-Halverson
Hans-Halverson deleted the faster-substring branch August 12, 2026 02:50
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.

1 participant