getsentry / rust-sourcemap

A library for rust that implements basic sourcemap handling
Other
224 stars 27 forks source link

Remove regex dependency for faster runtime, and compile #55

Closed willstott101 closed 1 year ago

willstott101 commented 1 year ago

My motivations here are to learn about, and ideally improve the performance of, rust-based frontend tooling.

Behaviour Changes

The regex crate is used in two separate parts of this lib, in both cases I have ended up making behavioural changes - which I can undo to be more compatible if desired.

unicode-id

I went ahead and used unicode-id as I stole the is_valid_start and is_valid_continue functions from swc@5a23949f swc_ecma_ast/src/ident.rs#L180 and unicode-id is what swc uses.

Measurements

Before After Notes
Test run (cargo test stdout report) ~1.0s ~0.7s Bare in mind that I added more tests
Compilation from scratch ~14.5s ~11.5s cargo build --release --examples --offline
read example size 4770336 4761136 - 9200 bytes
rewrite example size 4878184 4864792 - 13392 bytes
mitsuhiko commented 1 year ago

If we end up killing the old function name heuristic (which for what it’s worth I’m absolutely fine with) we probably at least want to point people towards an example of how this is best done instead. We could potentially even have a highly inefficient way here to optionally (behind a feature flag) use the scope crate.

willstott101 commented 1 year ago

Yeah the use of this identifier stuff is purely within get_original_function_name. Trying to use js-source-scopes within here might be a bit confusing though, as that crate appears to depend on this one...

Swatinem commented 1 year ago

yes, IMO this crate should be limited in scope to only sourcemaps. extracting function names (scope information) is a different concern.

I think we can eventually remove that stuff in a breaking release.