Skip to content

TypeScript/JavaScript

Unit ஒரு folder அல்லது ஒரு file
Bridge generate செய்யப்பட்ட binary wire கூட napi-rs அல்லது wasm-bindgen; classes மற்றும் async உட்பட
Record மற்றும் replay செய்றது Node, .ts sources-ஐ run பண்ணி
தேவைப்படுவது Node 22.6+ (profile-க்கு Node 24+ தேவை)
நிலை Verified

Bridge தேர்வு செய்யுறது

unit அல்லது அது import பண்ற எதுவும் Node-ஐ தேவைப்படுத்தினா analyze napi-rs-ஐ தேர்வு செய்யும், portable code-க்கு wasm-bindgen-ஐ (இது browsers-லயும் run ஆகும்) தேர்வு செய்யும், மேலும் UI மற்றும் editor code-ஐ JS-லயே வைக்கும். bridge --kind napi|wasm இதை override பண்ணும்.

Bridge-ஐ cross பண்ண முடியாத exports காரணத்தோட TS-லயே இருக்கும், மேலும் shadow module original-ஐ re-export பண்ணும்: functions-ஐ எடுத்துக்கிற அல்லது return பண்ற functions, generators மற்றும் iterators, RegExp, instanceof checks, generics (--as-json T app data-ஆ மட்டும் நிரப்புற ஒண்ணை bridge பண்ணும்), மற்றும் functions கொண்ட types-ஓட values. Bridge பாருங்க.

TS-ஐ அப்படியே record பண்றது

record TS sources-ஐ நேரடியா run பண்ணும்: ஒரு Node resolve hook bundler-style imports-ஐ follow பண்ணும், repo-ல எதுவும் install ஆகாதபோது --resolve-from npm packages-ஐ கொடுக்கும், transform தேவைப்படுற TS (enums, parameter properties) --experimental-transform-types-ஓட மறுபடி try பண்ணப்படும். record --from-tests -- npx jest original-ஓட சொந்த test suite செய்யுற ஒவ்வொரு call-ஐயும் எந்த runner கூடவும் record பண்ணும். TS/JS-க்கு original-ஓட coverage அளக்கப்படும் (Coverage).

ஒரு port சரியா செய்ய வேண்டியவை

Real code-ல record ஆன cases மூலமா கண்டுபிடிக்கப்பட்டது:

  • str.length, indexOf மற்றும் slice UTF-16 code units-ஐ count பண்ணும், அதனால ஒரு emoji இரண்டு positions ஆகும். generate செய்யப்பட்ட utf16 helpers-ஐ பயன்படுத்துங்க.
  • u flag இல்லாத /.../i non-ASCII case folding செய்யும்போது (/é/i "É"-ஐ match பண்ணும்), ASCII எழுத்துகளுக்கு fold ஆகுற Unicode எழுத்துகளை — long s (ſ) மற்றும் Kelvin sign (K) மாதிரியானவற்றை — u இல்லாம ASCII எழுத்துகளோட match பண்ணாது; ஆனா Rust-ஓட regex crate இயல்பாவே முழு Unicode case folding செய்யும், அதனால "1 ſ" (long s) மற்றும் Kelvin sign vercel/ms-ல seconds-ஆ parse ஆகியிருக்கும்.
  • Math.round halves-ஐ மேல round பண்ணும் (-2.5 என்பது -2 கொடுக்கும்); Rust-ஓட round zero-ல இருந்து விலகிப் போகும். generate செய்யப்பட்ட js.rs-ல js::math_round இருக்கு.
  • ${n} என்பது 1e+21, 5e-324 மற்றும் -0-க்கு 0 print பண்ணும். js::number_to_string அதை அப்படியே கொண்டு வரும்.
  • String.prototype.trim JS whitespace-ஐ பயன்படுத்தும், Rust-ஓட char::is_whitespace-ஐ இல்ல.

வேகம்

ஒரு call-க்கு, port ஒவ்வொரு முறையும் bridge-க்கான விலையைக் கொடுக்கும், மேலும் V8 சின்ன functions-ஐ nanoseconds-ல run பண்ணும். Record ஆன cases மேல vercel/ms ஒரு call-க்கு 0.56x வேகத்துல run ஆச்சு; x18n-ஓட core ports JS-ல இருந்து call பண்ணும்போது TS-ஐ விட மெதுவா இருக்கு. Batches-ஆ மாற்றும்போது, loop Rust-க்கு நகரும்:

Workload Original rust-anything கூட
Node-ல x18n-ஓட sidebar search, 50,000 keys query-க்கு 10 ms 0.5 ms: 20x வேகம்
Browser-ல அதே search (wasm, ஒரு thread) 10 ms 0.95 ms: 11.5x
Fuse.js, 50,000 strings 91.2 ms 2.8 ms: 32x
vercel/ms parse x100,000 11.8 ms 0.65 ms: 18x (handover-ஐ சேர்த்தா 3.4x)
vercel/ms format x100,000 2.1 ms handover கூட 2.5 ms: 0.8x

Case studies: json-server, Fuse.js, vercel/ms, x18n.

GitHub-ல இந்தப் பக்கத்தை edit பண்ணுங்க →