-
Notifications
You must be signed in to change notification settings - Fork 111
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
There are some js to c/wasm transpilers but: #24
Comments
. javy uses quickjs under the hood which is a javascript interpreter that can be run in wasm. But the javascript itself doesn't get compiled to wasm, only embedded in it as text. I used it before to evaluate some parts of the obfuscated code before but the reason was for sandboxing and not speed. |
what about v8-compile-cache?? |
For ease of others following along, these are the previous issues that this discussion has been fragmented across:
I haven't evaluated if it would fully cover your needs, but if you haven't already, you might like to look at
|
I experimented a while ago with using rust parsers and converting back to the babel AST format: https://github.com/coderaiser/swc-to-babel Another WIP JS-only attempt with https://github.com/meriyah/meriyah + https://github.com/j4k0xb/estree-to-babel/tree/perf could speed up parsing from |
@j4k0xb True true, that would definitely make sense. I haven't spent much time looking deeply into the combination of JS + webasm things, but I do remember there being something about the 'data transfer' between them being somewhat 'expensive'. How did you go about transfering the objects back to JS out of curiosity? I wonder if there are any methods that could be used to optimize that in a way that would speed things up; or alternatively, maybe a way to keep the actual AST objects within the rust side of things, but be able to manipulate them from JS functions/similar?
@j4k0xb Yeah, personally I would think optimising for the transform side of things makes the most sense as well. Not sure how often it would come up in reality, but one thing I was thinking about was for particularly large bundles, sometimes it might take an unreasonable amount of time and/or memory to try and unbundle them; and so was thinking that in a case like that, perhaps it could make sense to use a rust/etc based tool to first extract them into individual module files (as an example), and then potentially process them in a later 'unminify' step (that could potentially be JS based). That might not resolve anything anyway though, as the unminify step probably has to load the full JS context into memory to be able to unminify anyway, so it would probably just 'out of memory' at that point if it was going to. |
Its serializing it with serde_json::to_string and deserializing with JSON.parse.
Definitely a possibility, but again the whole project would have to be rewritten in rust
Do you have examples where this happens? The current time/memory usage is not that unreasonable imo:
I also thought about something similar where transforms could be performed in parallel for each module. |
(I thought I replied to this the other week, but apparently got distracted somewhere along the way.. 😅)
@j4k0xb True true, that doesn't look too bad all in all then.
@j4k0xb Yeah.. that would be less than ideal. I don't know how possible it is, or if there are existing libraries/etc that would make it easier, but my original thought in this area was if it was possible to basically 'describe the transformation to be made' on the JS side of things, and then pass that through to the rust side for it to do the 'heavy lifting'. If that were possible, then it should remove the need to convert the whole project to rust, and also would remove the performance penalty of needing to pass the whole AST back and forth across the rust/JS boundary. The 2 ways I was initially pondering that this might be possible were:
There was also one more idea I was pondering, though not sure if it would be impractical due to needing to cross back and forth across the rust/JS boundary (this idea is less thought through than the others above; and realistically could probably work with/alongside them, particularly the DSL idea):
Some related ideas/exploration based on the above potentials was:
@j4k0xb I don't personally have specific examples, and the one I was thinking of was using
|
The following may also be of interest:
If you get deeper into benchmarking/optimisation of the Rust side of things, this was a good read: Which I summarised the main points as:
|
So a transpiler that supported every js feature would still be slower overall.
https://www.assemblyscript.org is very similar to js/ts but would also require rewriting or substantially modifying all libs, in which case using another language is most likely a better choice
Originally posted by @j4k0xb in #23 (comment)
found this:
https://www.wasm.builders/gunjan_0307/compiling-javascript-to-wasm-34lk
The text was updated successfully, but these errors were encountered: