Commit graph

39 commits

Author SHA1 Message Date
Tim Fish
f6e42b6d85
feat(sourcemap): Add support for sourcemap debug IDs (#6221)
The sourcemap [`debugId`
proposal](https://github.com/tc39/source-map/blob/main/proposals/debug-id.md)
adds globally unique build or debug IDs to source maps and generated
code, making build artifacts self-identifying.

Support for debug IDs was added to
[`rust-sourcemap`](https://github.com/getsentry/rust-sourcemap/pull/66)
in 2023 and Sentry have made use of this to aid in matching up source
and sourcemap files without having to worry about path mismatches or
release versions.

I want to add debug ID support to Rolldown but it uses `oxc::sourcemap`
so it looks like I need to start here first!
2024-10-07 13:54:08 +08:00
Boshen
6f98aadc7f fix(sourcemap): align sourcemap type with Rollup (#6133)
closes #5578
2024-09-28 04:24:05 +00:00
dalaoshu
d18c896a2c
perf(rust): use cow_utils instead (#5664)
Related to #5586 and #5662

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-09-11 18:39:30 +08:00
rzvxa
5fd170140e refactor(sourcemap): lower the msrv. (#4873)
Related to https://github.com/oxc-project/oxc/pull/4864#issuecomment-2285908919
https://releases.rs/docs/1.80.0/#stabilized-apis
2024-08-13 10:52:34 +00:00
overlookmotel
e42ac3a2a0
feat(sourcemap): add ConcatSourceMapBuilder::from_sourcemaps (#4639)
Introduce new method `ConcatSourceMapBuilder::from_sourcemaps`.

Where all the sourcemaps being concatenated exist at time that you
create `ConcatSourceMapBuilder`, it's faster to use `from_sourcemaps`,
because it pre-allocates enough space for the data it will hold and so
avoids memory copying.

Before:

```rs
let mut builder = ConcatSourceMapBuilder::default();
builder.add_sourcemap(&sourcemap1, 0);
builder.add_sourcemap(&sourcemap2, 100);
builder.add_sourcemap(&sourcemap3, 100);
let combined = builder.into_sourcemap();
```

After:

```rs
let builder = ConcatSourceMapBuilder::from_sourcemaps(&[
    (&sourcemap1, 0),
    (&sourcemap2, 100),
    (&sourcemap3, 200),
]);
let combined = builder.into_sourcemap();
```
2024-08-06 14:08:17 +08:00
overlookmotel
ff43dff99d perf(sourcemap): speed up VLQ encoding (#4633)
Speed up source map VLQ encoding by removing a couple of operations from `serialize_mappings`'s hot loop.

On a local benchmark of just VLQ encoding, this change produces 5% performance increase (benchmarked on MacBook Pro M1).
2024-08-05 01:34:59 +00:00
overlookmotel
a3307734c5 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`.
2024-08-05 01:26:13 +00:00
overlookmotel
372316bf87 perf(sourcemap): ConcatSourceMapBuilder extend source_contents in separate loop (#4634)
Small optimization to source map concatenation. Check if input sourcemap has `source_contents` once, rather than on each turn of the loop.
2024-08-05 01:26:12 +00:00
overlookmotel
c7f1d48c0e perf(sourcemap): keep local copy of previous token in VLQ encode (#4596)
In source map VLQ encoding, keep local copy of previous `Token`, rather than looking up up from `tokens`.

On a local benchmark of just VLQ encoding, this change produces 6% performance increase (benchmarked on MacBook Pro M1).
2024-08-01 14:58:08 +00:00
overlookmotel
590d79530e perf(sourcemap): shorten main loop encoding VLQ (#4586)
Reduce number of operations in main loop in source map VLQ encoding.

#4583 made pushing a byte to output only 2 instructions, so that makes it workable to repeat `push_byte_unchecked` inside and outside the loop.

On a local benchmark of just VLQ encoding shows this increases performance by 16% (on top of the 11% from #4583).

Probably main gain is it makes a fast path for encoding `0`, which is common.
2024-08-01 12:21:26 +00:00
overlookmotel
d00014e4b5 perf(sourcemap): elide bounds checks in VLQ encoding (#4583)
In `oxc_sourcemap`'s VLQ encoding, avoid bounds checks when pushing bytes to the encoded string in the hot loop.

Those bounds checks are quite expensive as they involve a function call to `alloc::raw_vec::RawVec::grow_one`, and that happens on every single pushed byte.

https://godbolt.org/z/44G8jjss3

Not much difference on benchmarks, as VLQ encoding is only a small part of source map generation, but a local benchmark of just VLQ encoding shows this increases performance by 11%.
2024-08-01 08:34:15 +00:00
overlookmotel
7c42ffcd06
refactor(sourcemap): align Base64 chars lookup table to cache line (#4535)
Align the Base64 chars lookup table in sourcemap generator so it occupies a single cache line.
2024-07-30 04:28:10 +00:00
overlookmotel
27fd0628ef
refactor(sourcemap)!: avoid passing Results (#4541)
Refactor building sourcemap JSON to avoid passing `Result`s. `Serialize::serialize` is infallible here as writing to a `Vec<u8>` is infallible.
2024-07-30 04:23:49 +00:00
Brooooooklyn
1fd9dd0388
perf(sourcemap): use simd to escape JSON string (#4487)
Also optimize the memory allocation in string escape. The default size in `serde_json` is 1024 for String type, we pre allocate `string.len() * 2 + 2` for every string to reduce re-allocate in escaping.

I've tried to hand write SIMD implementation, but it's too complex, so I uses the `v_jsonescape` here. But it doesn't support `aarch64` and `wasm32` simd implementation, we need to contribute to it!
2024-07-29 12:42:21 +00:00
overlookmotel
5db7bed4f5 fix(sourcemap): fix pre-calculation of required segments for building JSON (#4490)
Fix the maths for calculating max number of segments required when building JSON source map.
2024-07-27 10:25:42 +00:00
overlookmotel
705e19f794 perf(sourcemap): reduce memory copies encoding JSON (#4489)
Reduce memory copies when encoding source map as JSON, extending approach taken in #4476 to also avoid memory copies for source texts.

I believe reason this shows no benefit on benchmarks is because our benchmarks only create a source map from a single source file, but it should result in a speed-up when there are multiple sources.
2024-07-27 10:25:40 +00:00
overlookmotel
c958a557fe refactor(sourcemap): push_list method for building JSON (#4486)
Follow up after #4476. Refactor to remove repeated code.
2024-07-27 10:25:38 +00:00
Brooooooklyn
4d10c6c9be
perf(sourcemap): pre allocate String buf while encoding (#4476)
I'm trying llama3.1:70b following [local-ai-copilot](https://developer.ibm.com/tutorials/awb-local-ai-copilot-ibm-granite-code-ollama-continue/) to find some potential performance improvement.

The code was not completed by AI; it only identified potential optimizations, which I am testing for effectiveness.
2024-07-26 13:58:09 +00:00
underfin
4cd5df00ea
fix(sourcemap): avoid negative line if token_chunks has same prev_dst_line (#4348) 2024-07-19 18:14:35 +08:00
underfin
205c259119
feat(sourcemap): support SourceMapBuilder#token_chunks (#4220)
Because the `token_chunks` need to pre-visit tokens and collect, it
could be done at add tokens phase. So here export it let rolldown could
be improve `renderChunks` sourcemap encode.
2024-07-13 10:11:14 +08:00
underfin
9e8709f06e
fix(sourcemap): should add tokens for unordered span (#3941)
close: https://github.com/oxc-project/oxc/issues/3843
2024-06-27 20:24:22 +08:00
underfin
d3cd3ea2de
feat: oxc transform binding (#3896)
closes #3877

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-26 21:57:19 +08:00
DonIsaac
01572f037d feat(sourcemap): impl std::fmt::Display for Error (#3902) 2024-06-26 05:10:48 +00:00
Boshen
051ceb6539
chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
Boshen
982e6f08df chore: make println and eprintln opt-in (#3712)
I noticed accidental `println` can be merged, which isn't really nice.
2024-06-17 10:40:34 +00:00
underfin
82c21f38f6
chore(sourcemap): make JSONSourceMap fileds public (#3385) 2024-05-22 20:15:24 +08:00
underfin
90d2d09022
feat(sourcemap): add Sourcemap#from_json method (#3361)
The rolldown plugin hook could return an object map, cast it to string
at node, and decode it has unnecessary json overhead at rust. So here
export an new function to let rolldown could using `JSONSourceMap` to
generate `Sourcemap`.
2024-05-20 22:35:14 +08:00
Boshen
899a52bf28
fix: fix some nightly warnings 2024-05-19 00:54:52 +08:00
Boshen
7363e14335
feat(sourcemap): add "rayon" feature (#3198) 2024-05-07 23:47:36 +08:00
underfin
8662f4f613
feat(sourcemap): add x_google_ignoreList (#2928) 2024-04-09 20:55:04 +08:00
underfin
5cb3991b67
feat(sourcemap): add sourceRoot (#2926) 2024-04-09 15:42:23 +08:00
renovate[bot]
cd6f4f1938
chore(deps): lock file maintenance rust crates (#2913) 2024-04-08 02:49:53 +00:00
underfin
96f02e6e21
feat(sourcemap): optional JSONSourceMap fileds (#2910)
Support optional JSONSourceMap fileds to support js side complex typing.
2024-04-07 23:32:12 +08:00
underfin
d87cf179a6
feat(sourcemap): add methods to mutate SourceMap (#2909) 2024-04-07 23:30:16 +08:00
underfin
74aca1c937
feat(sourcemap): add SourceMapBuilder file (#2908) 2024-04-07 23:29:25 +08:00
underfin
28fae2e80a
fix(sourcemap): using serde_json::to_string to quote sourcemap string (#2889) 2024-04-03 12:14:45 +08:00
underfin
64c4b825f1
chore: improve sourcemap visualizer (#2886)
The pr intend to improve `SourcemapVisualizer` log mapping.

- add the mapping for last token to final position of source
- fix token mapping
2024-04-03 10:45:00 +08:00
underfin
6177c2f7ef
fix(codegen): sourcemap token name should be original name (#2843)
close https://github.com/oxc-project/oxc/issues/2753.
2024-03-28 20:14:10 +08:00
underfin
b199cb89a2
feat: add oxc sourcemap crate (#2825)
The sourcemap implement port from
[rust-sourcemap](https://github.com/getsentry/rust-sourcemap), but has
some different with it.

- Encode sourcemap at parallel, including quote `sourceContent` and
encode token to `vlq` mappings.
- Avoid `Sourcemap` some methods overhead, like `SourceMap::tokens()`
caused extra overhead at common cases. Here using `SourceViewToken` to
instead of it.
2024-03-28 19:36:38 +08:00