mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(sourcemap): reduce string copying in ConcatSourceMapBuilder (#4638)
Clone `Arc<str>`s for source text instead of creating new `Arc<str>`s and copying the string data. For the shorter strings (names and source filenames) it's cheaper to create a new `Arc<str>` than to clone, presumably because of the overhead of atomic operations involved in `Arc::clone`.
This commit is contained in:
parent
372316bf87
commit
a3307734c5
1 changed files with 4 additions and 1 deletions
|
|
@ -49,7 +49,10 @@ impl ConcatSourceMapBuilder {
|
||||||
self.sources.extend(sourcemap.get_sources().map(Into::into));
|
self.sources.extend(sourcemap.get_sources().map(Into::into));
|
||||||
|
|
||||||
if let Some(source_contents) = &sourcemap.source_contents {
|
if let Some(source_contents) = &sourcemap.source_contents {
|
||||||
self.source_contents.extend(source_contents.iter().map(AsRef::as_ref).map(Into::into));
|
// Clone `Arc` instead of generating a new `Arc` and copying string data because
|
||||||
|
// source texts are generally long strings. Cost of copying a large string is higher
|
||||||
|
// than cloning an `Arc`.
|
||||||
|
self.source_contents.extend(source_contents.iter().map(Arc::clone));
|
||||||
} else {
|
} else {
|
||||||
self.source_contents.extend((0..sourcemap.sources.len()).map(|_| Arc::default()));
|
self.source_contents.extend((0..sourcemap.sources.len()).map(|_| Arc::default()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue