Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JavaScript Runtime とはなにか

JavaScript Runtime とはなにか

Yosuke Furukawa

August 21, 2024
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. Bun is a new JavaScript runtime built from scratch to

    serve the modern JavaScript ecosystem
  2. ݴޠ͸ compile time ͱ run time ʹ෼͔Ε ͯͯɺ run time

    ɺͭ·Γ࣮ߦதͷ࣌ʹඞཁ ͳ࢓૊ΈΛࢦͯ͠ Runtime System ΍ Runtime Environment, Runtime Library ͱݴͬͨΓ͢Δɻ
  3. JavaScript (+runtime) ػೳҰཡ • ࣈ۟ղੳ, ߏจղੳ (͍ΘΏΔ parser) • ߏจ࠷దԽ

    (͍ΘΏΔ JIT) • ϝϞϦ؅ཧ(ΨϕʔδίϨΫγϣϯ) • ΠϕϯτϋϯυϦϯά • ඇಉظॲཧػߏ • CPUந৅Խ • OSந৅Խ • File/Storage IO, Network IO • JS API (String, Number, etc) • ଞ API (DOM, Network, etc)
  4. JavaScript (+runtime) ػೳҰཡ • ࣈ۟ղੳ, ߏจղੳ (͍ΘΏΔ parser) • ߏจ࠷దԽ

    (͍ΘΏΔ JIT) • ϝϞϦ؅ཧ(ΨϕʔδίϨΫγϣϯ) • ΠϕϯτϋϯυϦϯά • ඇಉظॲཧػߏ • CPUந৅Խ • OSந৅Խ • File/Storage IO, Network IO • JS API (String, Number, etc) • ଞ API (DOM, Network, etc) JS Engine ͷػೳ Runtime ͷػೳ ྆ํ ͷػೳ
  5. Πϝʔδ JS Runtime JS Engine Parser JIT Memory Management CPU

    JS API (String, Number etc) Async Processing File Storage IO, Network IO Event Handling OS Other API (DOM, Network etc)
  6. Runtime ͱ͸ͳʹ͔ • Compile time / run time Ͱ෼͚ͨͱ͖ͷ࣮ߦதͷಈ͖ʹؔ͢Δ΋ͷΛࢦ ͢ɻ

    • ࣮͸ఆٛ͸ᐆດ • ʮ xxx ͸ Runtime ͳΜͰ͔͢?ʯΈ͍ͨͳ࣭໰͸͋·Γ͠ͳ͍ɻ • ݴޠͷίΞͱͳΔػೳ͕͋ΓɺͦͷपลΛͲ͏දݱ͢Δ͔Ͱܾ·Δɻ • ͔ͩΒΘ͔Γʹ͍͘ɺΘ͔ͬͨΑ͏ͰΘ͔Βͳ͍ɻ
  7. JavaScript ʹ͓͚Δ Runtime ͸Կ͕දݱ ͞ΕͯΔ͔ • ΠϕϯτϋϯυϦϯά • ඇಉظॲཧػߏ •

    File IO • Network IO • OSந৅Խ • ͦΕΒΛѻ͏ͨΊͷAPI • DOM • Network (fetch etc) • fs, http, child_process • etc
  8. ڞ௨ઓུ • WinterCG΁ͷରԠΛਐΊͭͭɺ͓ޓ͍ͷྑ͍ͱ͜Ζ͕͋Ε͹ޙ௥͍Ͱ࠾༻͍ͯ͘͠ํ਑ • Node.js Ͱ͸࠷৽Ͱ strip-types ΍ storage ͷରԠ͕ਐΜͰΔ(Deno,

    Bunͷػೳ΁ͷ௥ै) • Deno͸Node.js Compatibility Λ্͛ͯnpmͷࢿ࢈΋࢖͑ΔΑ͏ʹ͍ͯ͠Δ(Node.jsطଘ ࢿ࢈΁ͷ௥ै) • Bun͸ WinterCG ΁͸ࢀՃද໌͍ͯ͠ͳ͍͕ɺ Web API Interop ͸Ͱ͖ΔൣғͰਐΊͯ Δɻ͞ΒʹNode.jsͷCompatibilityΛ্͛ͯnpmͷࢿ࢈΋࢖͑ΔΑ͏ʹ͍ͯ͠Δ(Node.js طଘࢿ࢈΁ͷ௥ै)
  9. ࠩผԽϙΠϯτ • Deno • ͻͱͭ͸ηΩϡϦςΟॏࢹɺOSͷػೳΛ࢖͏ࡍʹύʔϛογϣϯ͕ཁ ٻ͞ΕΔͨΊɺҙਤ͠ͳ͍ϑΝΠϧૢ࡞΍ωοτϫʔΫૢ࡞Λ๷͛Δ • Deno Fresh ͳͲͷ

    ϑϨʔϜϫʔΫ΋ެ͕ࣜಉ͡organizationͰ։ൃ͠ ͓ͯΓɺपลͷπʔϧྨ͸ͦ͜Ͱαϙʔτ͞ΕͯΔҹ৅ɻ • Կͱݴͬͯ΋࠷ۙ͸JSRɺJavaScript Registry ͱͯ͠ొ৔ɻ
  10. ࠩผԽϙΠϯτ • Deno • JSR • TypeScript Λͦͷ··ιʔεͱͯ͠publishͯ͠ɺதͰίϯύΠϧͯ͠JavaScriptʹม׵Ͱ ͖Δ •

    npm ͷ publish ઌ͔Β JSR Λܦ༝ͯ࣋ͬͯ͘͠Δ͜ͱ΋Ͱ͖ΔͷͰɺطଘࢿ࢈͔ΒͷҠ ߦ΋Ͱ͖Δ • ԿΑΓɺ ESM Λ࠷ॳͷλʔήοτͱ͢ΔͷͰɺ CJS ͕جຊʹͳ͍ͬͯΔ npm ͱ͸Ұઢ Λը͢ ৽͍͠ϨδετϦΛඋ͑ͯɺNode.js͔ΒϢʔβʔΛͲ͜·Ͱ࣋ͬͯ͜ΕΔ͔
  11. ࠩผԽϙΠϯτ • Bun • package.json Ͱ͸উखʹ jsonc ࢖ͬͯΔ͠ɺ console ͸

    async iterationͩ͠ɺΊͪΌͪ͘Όಠࣗ࿏ઢɻ • Զͷ࠷ڧͷ runtime Λ࡞ͬͯ΍Δͥײ͕͋Δɻ • ݏ͍͡Όͳ͍ɻ Performance is all you need!! And crazy ideas are all I need!!!
  12. ମ੍ • Deno: • Ϧʔμʔ: Ryan Dahlࢯ • OSS։ൃऀͱDeno CompanyͰͷձࣾ։ൃͷϋΠϒϦου

    • ։ൃϓϩηε͸جຊΦʔϓϯɺ(Issue, PR, RFC) • Deno Deploy ͷ঎༻ࢧԉͳͲ΋͋ΓɺίϛϡχςΟͱίΞνʔϜͱ঎༻ࢧԉ ͞ΕͯΔνʔϜͷࡾҐҰମ Redisͱ͔VercelͷOSS + ঎༻ͰͷઓུʹࣅͯΔ
  13. ମ੍ • Bun: • Ϧʔμʔ: Jarred Summerࢯ • BunΛfull timeͰ։ൃ͠ɺ

    ϗεςΟϯά؀ڥͳͲΛ࡞ͬͯJS։ൃମݧΛ޲্ͤ͞ Δ໊໨Ͱձࣾ΋্ཱͪ͛ͯΔ (Oven)ɻ • OSS Contributors + ovenࣾͷϋΠϒϦουମ੍ • ঎༻Ϣʔεέʔεͱ͔͸ฉ͍ͨ͜ͱແ͍ͷͰɺϚωλΠζΛͲ͏͢Δͷ͔͸ෆ໌ ମ੍͸࡞ΒΕͯΔ͚Ͳɺ·ͩ͜Ε͔Βײ͕͋Δɻ