Skip to content

Conversation

@SyMind
Copy link
Collaborator

@SyMind SyMind commented Oct 30, 2025

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() using OnceLock to avoid repeated calculations
  • Added comprehensive test case and benchmark for the new size calculation logic

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 30, 2025

CodSpeed Performance Report

Merging #193 will not alter performance

Comparing perf-replace-source-size (74b8ac2) with main (42b4f9f)

Summary

✅ 10 untouched
🆕 1 new
⏩ 5 skipped1

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 complex_replace_source_size N/A 294.1 µs N/A

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@SyMind
Copy link
Collaborator Author

SyMind commented Oct 30, 2025

image

@SyMind SyMind marked this pull request as ready for review October 30, 2025 06:24
Copilot AI review requested due to automatic review settings October 30, 2025 06:24
Copy link

Copilot AI left a 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() using OnceLock to 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.

@SyMind SyMind merged commit c5b3502 into main Oct 30, 2025
10 checks passed
@SyMind SyMind deleted the perf-replace-source-size branch October 30, 2025 06:31
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.

2 participants