Skip to content
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

perf: pre-allocate text change string capacity #289

Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Dec 8, 2024

Pretty trivial to maintain this now.

use deno_ast::apply_text_changes;
use deno_ast::TextChange;

fn main() {
  let mut value = 0;
  let mut large_string = String::new();
  for _ in 0..10000 {
    large_string.push_str("testing this out");
  }
  let changes = vec![TextChange::new(9, 10, "z".to_string()), TextChange::new(4, 6, "y".to_string()), TextChange::new(1, 2, "x".to_string())];
  for _ in 0..10000 {
    let final_str = apply_text_changes("testing this out", changes.clone());
    value += final_str.len();
  }
  eprintln!("start: {}", value);
}
> hyperfine --warmup 4 "before.exe" "after.exe"
Benchmark 1: before.exe
  Time (mean ± σ):       6.9 ms ±   0.6 ms    [User: 1.1 ms, System: 1.0 ms]
  Range (min … max):     5.9 ms …   9.5 ms    259 runs

Benchmark 2: after.exe
  Time (mean ± σ):       6.4 ms ±   0.5 ms    [User: 0.2 ms, System: 0.8 ms]
  Range (min … max):     5.6 ms …   8.5 ms    302 runs

Summary
  after.exe ran
    1.08 ± 0.12 times faster than before.exe

Closes #140

@dsherret dsherret requested a review from bartlomieju December 16, 2024 20:24
@dsherret dsherret merged commit 4b90da4 into denoland:main Dec 29, 2024
2 checks passed
@dsherret dsherret deleted the perf_preallocate_text_change_capacity branch December 29, 2024 23:10
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.

Preallocate apply_text_changes result
2 participants