TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Oxidizing Source Maps with Rust and WebAssembly

207 pointsby mnemonikover 7 years ago

7 comments

MrBingleyover 7 years ago
&gt; Tom Tromey and I have replaced the most performance-sensitive portions of the source-map JavaScript Library’s source map parser with Rust code that is compiled to WebAssembly. The WebAssembly is up to 5.89 times faster than the JavaScript implementation on realistic benchmarks operating on real world source maps.<p>Wow. Some people have been wondering if Rust has a &quot;killer app&quot;, but this could be it. Right now WebAssembly only supports non-GC languages (so C, C++, and Rust), and of those three Rust is the easiest to get started with. It looks really appealing.
评论 #16180436 未加载
评论 #16182390 未加载
评论 #16180452 未加载
kbensonover 7 years ago
Wow, I had assumed a lot more of the Rust runtime&#x2F;stdlib would need to come along with anything, but the wasm-unknown-unknown target and aggressive culling of unused code looks to make this really competitive. That&#x27;s awesome, and I&#x27;m really happy to have my predictions and assumptions proven wrong. :)<p>Edit: Some of the numbers:<p>Original JS: just under 30,000 bytes.<p>Closure compiler minified JS: 8,365 bytes.<p>New combined JS and WASM: 20,996 bytes<p>Roughly half of the WASM output is JS and half of which is WASM, since not all components in the original JS were replaced, just a specific subset. There is some duplication of functions that both the remaining JS still uses and the new WASM code does as well. Rust diagnostic and error messages appear to still be present inthe data section although unusable, so could be cleared out with better tooling.
评论 #16181774 未加载
ridiculous_fishover 7 years ago
VLQ decoding is sort of subtle, and the one shown in the article under &quot;Base 64 Variable Length Quantities&quot; looks broken.<p>1. `shift` can grow large, and an overlong left shift will panic in Rust. I expect an input like &quot;gggggggC&quot; to crash.<p>2. `accum &gt;&gt;= 1` is wrong because it rounds down. It needs to be a round-towards-zero: `accum &#x2F;= 2`.<p>3. `accum` is a 32 bit int which is too small. It needs to be larger so it can represent -2^31 in sign-magnitude form.
评论 #16181401 未加载
js2over 7 years ago
FYI, the Sentry folks have also written a Rust-based sourcemap decoder:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;getsentry&#x2F;rust-sourcemap" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;getsentry&#x2F;rust-sourcemap</a>
评论 #16185674 未加载
couchandover 7 years ago
This is brilliant. Very excited to see more applications like this making great use of the possibilities of Rust+WASM.<p>One thing that stuck out to me was the exploded-struct callback mechanism for reporting Mappings back to JS. I&#x27;ve also been struggling to handle the low-bandwidth interface between JS and WASM. That wasn&#x27;t a strategy I&#x27;d considered, but it&#x27;s pretty neat.<p>It&#x27;s simple enough and will work in this case, but unfortunately doesn&#x27;t generalize very well. I&#x27;ve been exploring using well-defined binary encoding for this purpose (specifically Cap&#x27;n&#x27;Proto, but Protobuf or another binary encoding would work, too).<p>See an example I put together: <a href="https:&#x2F;&#x2F;github.com&#x2F;couchand&#x2F;rust-wasm-capnproto-example" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;couchand&#x2F;rust-wasm-capnproto-example</a>. I&#x27;m definitely going to go back and clean that up with some of the FFI patterns from this article.
eridiusover 7 years ago
parse_mappings is incorrect. It has the following line:<p><pre><code> Vec::&lt;usize&gt;::from_raw_parts(capacity_ptr, size, capacity); </code></pre> But size is wrong. size here is the number of bytes that JavaScript instructed Rust to allocate. It&#x27;s not the size of the Vec::&lt;usize&gt;.<p>This should be harmless as the resulting Vec is immediately deallocated, so the only thing that size is used for is deinitializing values, and since the values are usize there&#x27;s nothing to deinitialize. But it&#x27;s still technically incorrect.
评论 #16188444 未加载
eridiusover 7 years ago
The get_last_error() snippet shows LAST_ERROR as being a static mut (which IIRC requires unsafe access as it&#x27;s not thread-safe). But the parse_mappings() snippet shows safe access to LAST_ERROR using an API that clearly indicates it&#x27;s not just an Option. I assume that at this point it&#x27;s actually a std::thread::LocalKey.
评论 #16188232 未加载