-
Notifications
You must be signed in to change notification settings - Fork 9
perf: replace source size #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CodSpeed Performance ReportMerging #193 will not alter performanceComparing Summary
Benchmarks breakdown
Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the size() method implementation for ReplaceSource to calculate the accurate size by simulating the replacement process, rather than simply returning the byte length of the original source. This ensures the size reflects the actual output after all replacements are applied.
- Implemented accurate size calculation in
ReplaceSource::size()by iterating through replacements and adjusting for length differences - Added caching for
CachedSource::size()usingOnceLockto avoid repeated calculations - Added comprehensive test case and benchmark for the new size calculation logic
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/replace_source.rs | Replaced simple byte length calculation with accurate size simulation that accounts for all replacements; added test case validating size matches generated content |
| src/cached_source.rs | Added size caching using OnceLock to improve performance by avoiding redundant size calculations |
| benches/bench_complex_replace_source.rs | Added benchmark function for measuring size() performance on complex replace sources |
| benches/bench.rs | Integrated new size benchmark into the benchmark suite |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This PR optimizes the
size()method implementation forReplaceSourceto calculate the accurate size by simulating the replacement process, rather than simply returning the byte length of the original source. This ensures the size reflects the actual output after all replacements are applied.ReplaceSource::size()by iterating through replacements and adjusting for length differencesCachedSource::size()usingOnceLockto avoid repeated calculations