Skip to content

perf: Replace pushback with rewinding#11

Merged
kitten merged 10 commits intomainfrom
@kitten/perf/replace-pushback-with-rewind
Nov 27, 2025
Merged

perf: Replace pushback with rewinding#11
kitten merged 10 commits intomainfrom
@kitten/perf/replace-pushback-with-rewind

Conversation

@kitten
Copy link
Copy Markdown
Owner

@kitten kitten commented Nov 27, 2025

Summary

Instead of pushing back actual data and storing it, we can instead use the fact that we're only replaying bytes that have just been returned. This allows us to rewind() a few bytes, instead of copying them into a buffer. This is possible due to block.copyWithin. For cases where we only returned input bytes directly, this is even simpler, since we can store an offset, avoid subarray, and subtract from the offset.

Set of changes

  • Always allow partial returns on read()
  • Switch input on reader.ts to be offset based and defer subarray calls
  • Replace pushback() logic with rewind()
  • [unrelated] Replace copyUint8Array with slice
  • [unrelated] Share intermediary buffer copy for readUntilBoundary on reader
  • [unrelated] Pass in skip table externally as arguments
  • [unrelated] Replace expectTrailer with direct read() call
  • Add missing copyless return optimization to buffered input path, which is now possible

@kitten kitten merged commit d18a0af into main Nov 27, 2025
2 checks passed
@github-actions github-actions bot mentioned this pull request Nov 27, 2025
@kitten kitten deleted the @kitten/perf/replace-pushback-with-rewind branch February 16, 2026 03:25
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