Use SWC to parse and transform code instead of Babel #1365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proof of concept in replacing Babel in the compilation step, it probably is not ready for merge given it's limited testing (hence the draft PR) but I think it's at a stage for potential discussion.
The positives here are mostly around the faster build time, I am limited on what I have to test but there appears to be a consistent speed up between the Babel based Alloy and SWC based Alloy (benchmarks and testing method below)
Default app
alloy compile /Users/awam/Documents/titanium-workspace/test-app/app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator
alloy2 compile /Users/awam/Documents/titanium-workspace/test-app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator
Benchmark command
`hyperfine --prepare 'ti clean' --runs 10 'alloy compile /Users/awam/dev/git/tidev/kitchensink-v2/app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator' 'alloy2 compile /Users/awam/dev/git/tidev/kitchensink-v2/app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator'`KitchenSink
alloy compile /Users/awam/dev/git/tidev/kitchensink-v2/app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator
alloy2 compile /Users/awam/dev/git/tidev/kitchensink-v2/app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator
Benchmark command
hyperfine --prepare 'ti clean' --runs 10 'alloy compile /Users/awam/Documents/titanium-workspace/test-app/app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator' 'alloy2 compile /Users/awam/Documents/titanium-workspace/test-app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator'However, there are some potential drawbacks here:
If this proves useful, and there is consensus we could potentially make this an opt-in thing via a config setting to allow testing over time before making it the default.
There are some areas also that could be investigated to improve:
Testing
If you're curious in testing this you can install it using
npm i tidev/alloy#feat/use-swc -g
. Please provide any feedback you may have!Other things
One potential question here is "what about X?", and that would be a good one, I just went with SWC as it seemed a good choice. I think it would also be worthwhile to investigate whether it's feasible to do this with maybe esbuild or simply just acorn (maybe even though it's JS it is faster than babel?). I plan to give these a try if I can find some time.