SlideShare a Scribd company logo
A glance at the SWC
Speedy web compiler - written in Rust
About
- An extensible Rust-based platform for the next generation of fast developer
tools
- Main features: transform (to ecma targets, add new syntaxes,... ),
bundling(swcpack - still in development), ast parser,
- Used by tools like Next.js, Parcel, and Deno, the list goes on
- Used by companies like Vercel, ByteDance, Tencent, Shopify, etc.
*** SWC is 20x faster than Babel on a single thread and 70x faster on four cores.
(according to swc.rc)
Why SWC (pros)
Extensibility: allow extend features with plugin, in js(have bottleneck issue) or in rust
Performance: see page 2. (picture below: benchmarks for transform to es5)
WebAssembly: support for WASM => super fast even in browser environment
Community: ecosystem are bing and still expanding.
Why not SWC (cons)
Rust is new to learn:
Challenging learning curve —>
Bottleneck with other tools:
It can make the build process faster, but it may
not, if we have still Webpack, legacy babel
loaders, or swc js plugin in the pipe, to do
some work.
Source: humb1t
Why not SWC (cons)
Rust is new to learn:
Challenging learning curve —>
Bottleneck with other tools:
It can make the build process faster, but it may
not, if we have still Webpack (or with some
legacy babel loaders) in the pipe, to do some
work.
Source: humb1t
How SWC runs in Node/ Browser
On Nodejs:
using Foreign Function Interface (via Node C++ AddOn, https://nodejs.org/api/addons.html)
On Browser:
Rust core => Wasm => run directly in browser(see @swc/wasm )
plugin: javascript plugin
- Like babel plugin, but interfaces are not
- Have bottleneck issue: because the core which is written in rust has a high
performance but js plugin, which traveling on AST, is not
- Showcase: @formatjs/swc-plugin
Native Rust plugins
Extend from babel: see https://swc.rs/docs/migrating-from-babel
Provide from swc_project: see github.com/swc-project/plugins
Custom plugins:
=> To have a glance: let’s make one simple plugin
Example and practice
Setup env:
# install rust via rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# install rust cli
cargo install swc_cli
# VSCODE setup rust language server
code --install-extension rust-lang.rust-analyzer
Example and practice
clone source plugin source code
# for quicker setup, clone this repository:
github.com/cute-me-on-repos/test-ts-miniapp.git
git checkout -b main/<.>
Example and practice
Init source plugin source code (target wasm32-wasi):
# init plugin with the name “tini-swc-plugin”:
swc plugin new --target-type wasm32-wasi tini-swc-plugin;
rustup target add wasm32-wasi # add target
cd tini-swc-plugin
Example and practice
Explaining simple example from document:
https://swc.rs/docs/plugin/ecmascript/getting-started
Then write our own one —> next page
Example and practice
# Practice problem:
Problem:
We want to limit some of the web Apis that users want to access in tini app;
Write a swc rust plugin to travel the AST of 1 js file and replace all statements
(include [`this`, `self`, `global`]) that refer to the global scope, except `this`
of Component/Page/App, with `(void 0)`(undefined).
Requirement: quick docs researching skill =))
Example and practice
# input:
```js
this;global; // thoses should be remove
global.unAllowWebApiCall();
(function unknow(){
this.unAllowWebApiCall();
})();
Page({
onLoad(){this.setData({value:”hi”})}
})
```
Example and practice
# output:
```js
(void 0);(void 0);
(void 0).unAllowWebApiCall();
(function unknow(){
(void 0).unAllowWebApiCall();
})();
Page({
onLoad(){this.setData({value:”hi”})}
})
```
Speed up Jest
In jest-transform pipe.
Addition: Rust to Wasm
- Light weight: rust have no GC -> not need to re-create GC in wasm like others
- Fast, safe, simple -> compare to cpp
? should
ArrayBuffer to transferring data between web contexts
(Q&&A)||SIGTERM
Gracias ♡ ~

More Related Content

PPTX
Introduction to Rust (Presentation).pptx
Knoldus Inc.
 
PPTX
Rust Melbourne MeetUp - Rust Web Development
Bastian Gruber
 
PPTX
Rust 101 (2017 edition)
Robert 'Bob' Reyes
 
PDF
The Rust Programming Language
Mario Alexandro Santini
 
PPTX
Rust programming-language
Mujahid Malik Arain
 
PPTX
Rust
Naga Dinesh
 
PDF
Rust: Systems Programming for Everyone
C4Media
 
PDF
Do things faster and better with WebAssembly - Sendil Kumar Nellaiyapen - Cod...
Codemotion
 
Introduction to Rust (Presentation).pptx
Knoldus Inc.
 
Rust Melbourne MeetUp - Rust Web Development
Bastian Gruber
 
Rust 101 (2017 edition)
Robert 'Bob' Reyes
 
The Rust Programming Language
Mario Alexandro Santini
 
Rust programming-language
Mujahid Malik Arain
 
Rust: Systems Programming for Everyone
C4Media
 
Do things faster and better with WebAssembly - Sendil Kumar Nellaiyapen - Cod...
Codemotion
 

Similar to A glance at the Rust SWC (20)

PPTX
From NodeJS to Rust
Bastian Gruber
 
PDF
What's wrong with web
Sergey Rubanov
 
PDF
First Step towards WebAssembly with Rust
Knoldus Inc.
 
PDF
WebAssembly
Jens Siebert
 
PDF
WebAssembly - czy dzisiaj mi się to przyda do pracy?
Brainhub
 
PDF
NATS Connect Live!
NATS
 
PDF
Mozilla + Rust at PCU Manila 02 DEC 2016
Robert 'Bob' Reyes
 
PDF
Rusted Ruby
Ian Pointer
 
PDF
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JSFestUA
 
PPTX
Web assembly with go
WangChow1
 
PDF
Practical WebAssembly with Apex, wasmRS, and nanobus
Jarrod Overson
 
PDF
WebAssembly with Rust
Knoldus Inc.
 
PPTX
MozillaPH Rust Hack & Learn Session 1
Robert 'Bob' Reyes
 
PPTX
How Servo Renders the Web
Adenilson Cavalcanti
 
PPTX
Web assembly - Future of the Web
CodeValue
 
PDF
Web Assembly
Valerio Como
 
PDF
WASM! WASI! WAGI! WAT?
Stefan Baumgartner
 
PDF
Igalia Focus and Goals 2020 (2019 WebKit Contributors Meeting)
Igalia
 
PDF
WebAssembly with Rust
Knoldus Inc.
 
PDF
Porting a Streaming Pipeline from Scala to Rust
Evan Chan
 
From NodeJS to Rust
Bastian Gruber
 
What's wrong with web
Sergey Rubanov
 
First Step towards WebAssembly with Rust
Knoldus Inc.
 
WebAssembly
Jens Siebert
 
WebAssembly - czy dzisiaj mi się to przyda do pracy?
Brainhub
 
NATS Connect Live!
NATS
 
Mozilla + Rust at PCU Manila 02 DEC 2016
Robert 'Bob' Reyes
 
Rusted Ruby
Ian Pointer
 
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JSFestUA
 
Web assembly with go
WangChow1
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Jarrod Overson
 
WebAssembly with Rust
Knoldus Inc.
 
MozillaPH Rust Hack & Learn Session 1
Robert 'Bob' Reyes
 
How Servo Renders the Web
Adenilson Cavalcanti
 
Web assembly - Future of the Web
CodeValue
 
Web Assembly
Valerio Como
 
WASM! WASI! WAGI! WAT?
Stefan Baumgartner
 
Igalia Focus and Goals 2020 (2019 WebKit Contributors Meeting)
Igalia
 
WebAssembly with Rust
Knoldus Inc.
 
Porting a Streaming Pipeline from Scala to Rust
Evan Chan
 
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Doc9.....................................
SofiaCollazos
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Ad

A glance at the Rust SWC

  • 1. A glance at the SWC Speedy web compiler - written in Rust
  • 2. About - An extensible Rust-based platform for the next generation of fast developer tools - Main features: transform (to ecma targets, add new syntaxes,... ), bundling(swcpack - still in development), ast parser, - Used by tools like Next.js, Parcel, and Deno, the list goes on - Used by companies like Vercel, ByteDance, Tencent, Shopify, etc. *** SWC is 20x faster than Babel on a single thread and 70x faster on four cores. (according to swc.rc)
  • 3. Why SWC (pros) Extensibility: allow extend features with plugin, in js(have bottleneck issue) or in rust Performance: see page 2. (picture below: benchmarks for transform to es5) WebAssembly: support for WASM => super fast even in browser environment Community: ecosystem are bing and still expanding.
  • 4. Why not SWC (cons) Rust is new to learn: Challenging learning curve —> Bottleneck with other tools: It can make the build process faster, but it may not, if we have still Webpack, legacy babel loaders, or swc js plugin in the pipe, to do some work. Source: humb1t
  • 5. Why not SWC (cons) Rust is new to learn: Challenging learning curve —> Bottleneck with other tools: It can make the build process faster, but it may not, if we have still Webpack (or with some legacy babel loaders) in the pipe, to do some work. Source: humb1t
  • 6. How SWC runs in Node/ Browser On Nodejs: using Foreign Function Interface (via Node C++ AddOn, https://nodejs.org/api/addons.html) On Browser: Rust core => Wasm => run directly in browser(see @swc/wasm )
  • 7. plugin: javascript plugin - Like babel plugin, but interfaces are not - Have bottleneck issue: because the core which is written in rust has a high performance but js plugin, which traveling on AST, is not - Showcase: @formatjs/swc-plugin
  • 8. Native Rust plugins Extend from babel: see https://swc.rs/docs/migrating-from-babel Provide from swc_project: see github.com/swc-project/plugins Custom plugins: => To have a glance: let’s make one simple plugin
  • 9. Example and practice Setup env: # install rust via rustup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # install rust cli cargo install swc_cli # VSCODE setup rust language server code --install-extension rust-lang.rust-analyzer
  • 10. Example and practice clone source plugin source code # for quicker setup, clone this repository: github.com/cute-me-on-repos/test-ts-miniapp.git git checkout -b main/<.>
  • 11. Example and practice Init source plugin source code (target wasm32-wasi): # init plugin with the name “tini-swc-plugin”: swc plugin new --target-type wasm32-wasi tini-swc-plugin; rustup target add wasm32-wasi # add target cd tini-swc-plugin
  • 12. Example and practice Explaining simple example from document: https://swc.rs/docs/plugin/ecmascript/getting-started Then write our own one —> next page
  • 13. Example and practice # Practice problem: Problem: We want to limit some of the web Apis that users want to access in tini app; Write a swc rust plugin to travel the AST of 1 js file and replace all statements (include [`this`, `self`, `global`]) that refer to the global scope, except `this` of Component/Page/App, with `(void 0)`(undefined). Requirement: quick docs researching skill =))
  • 14. Example and practice # input: ```js this;global; // thoses should be remove global.unAllowWebApiCall(); (function unknow(){ this.unAllowWebApiCall(); })(); Page({ onLoad(){this.setData({value:”hi”})} }) ```
  • 15. Example and practice # output: ```js (void 0);(void 0); (void 0).unAllowWebApiCall(); (function unknow(){ (void 0).unAllowWebApiCall(); })(); Page({ onLoad(){this.setData({value:”hi”})} }) ```
  • 16. Speed up Jest In jest-transform pipe.
  • 17. Addition: Rust to Wasm - Light weight: rust have no GC -> not need to re-create GC in wasm like others - Fast, safe, simple -> compare to cpp
  • 18. ? should ArrayBuffer to transferring data between web contexts