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

Denoの仕組み / How deno works as TypeScript runtime

5d769d109697012317c09c6a27a6a4bf?s=47 linyows
August 23, 2021

Denoの仕組み / How deno works as TypeScript runtime

Fukuoka.ts#3 Aug 23, 2021 での発表です。

5d769d109697012317c09c6a27a6a4bf?s=128

linyows

August 23, 2021
Tweet

Transcript

  1. Fukuoka.ts #3 TS How deno works as TS runtime Tomohisa

    Oda — GMO Pepabo, Inc. / Aug 23th 2021
  2. Fukuoka.ts #3 linyows / Tomohisa Oda GMO Pepabo, Inc.: Senior

    Engineering Lead Blog: https://tomohisaoda.com 2
  3. Fukuoka.ts #3 3 Private Projects ΞϓϦέʔγϣϯࣗ਎͕ϦϙδτϦ͔ Β࠷৽ͷίʔυΛݕ஌ͯࣗ͠ಈͰσϓϩ ΠͱσϦόϦʔΛߦ͏πʔϧ linuxͷuser໊લղܾΛGitHubͷ Teamϝϯόʔ΍ϦϙδτϦͷΞΫηε

    ݖݶऀ͔Βߦ͏πʔϧ ϝʔϧૹ৴༻ͷಁաܕSMTPϓϩΩγͰ ϦΫΤετͱϨεϙϯεΛϩά΍σʔλ ϕʔεʹग़ྗ͢Δ͜ͱ͕Ͱ͖Δ New!!
  4. Fukuoka.ts #3 ͓࿳ͼɿDenoਂງΓ👉Denoͷ࢓૊Έ 4

  5. Fukuoka.ts #3 Denoͱ͸ʁ Deno͸ɺ@ry͕nodejsͰޙչ͍ͯ͠Δ͜ͱʢgyp΍node_modules΍promiseͳͲʣ͔ΒϓϩδΣΫ τΛ։࢝ɻV8Λϥοϓͨ͠Rust੡ͷTypeScript/JavaScript ϥϯλΠϜɻϥϯλΠϜ୯ମͱ͍͏ΑΓ͸ ͦΕΛؚΊͨπʔϧνΣʔϯɻ ҎԼɺΦϑΟγϟϧ͔Βɻhttps://deno.land/ • σϑΥϧτͰηΩϡΞ

    👉 deno run —allow-net —allow-read foo.ts • TypeScriptΛͦͷ··αϙʔτ 👉 tsc΍swc͕಺෦Ͱ࢖ΘΕ͍ͯΔ • γϯάϧϑΝΠϧͷΈͰಈ͘ 👉 deno compile foo.ts => file • ґଘؔ܎ݕࠪ΍ϑΥʔϚοτ༻ͷπʔϧͳͲಉࠝ 👉 deno info, deno fmt, deno test… • ಈ࡞อূͷඪ४Ϟδϡʔϧ 5
  6. Fukuoka.ts #3 Denoͷߏ੒ ෳ਺ͷίϯϙʔωϯτʹ෼ׂ͞Ε͍ͯͯɺ3rd Party͕ଟ༻͞Ε͍ͯΔɻ3rd Party͕ॏཁͳϙδγϣϯʹΔͨΊɺͦΕΒΛִ཭͢ΔϨΠϠʔߏ੒ʹͳͬ ͍ͯΔɻ deno_core(rusty_v8(v8(js & wasm)))

    Έ͍ͨͳײ͡ɻ • RustͷඇಉظϥϯλΠϜTokioΛ࢖͍ͬͯΔ • RustͱV8ͷBindingsʹ͸rusty_v8͕୲͍ͬͯͯͦΕ΋3rd Party • TS͸ඪ४Ϟδϡʔϧ 6
  7. Fukuoka.ts #3 7 https://choubey.gitbook.io/internals-of-deno/architecture/overall-architecture

  8. Fukuoka.ts #3 V8ͱRustͷ໾ׂ෼୲ deno͸༷ʑͳίϯϙʔωϯτ͕͋ΓଞݴޠͰߏ੒͞Ε͍ͯΔɻ௒ઈࡶʹ͍͏ͱɺdeno͸V8ͷϥούʔ Ͱ͋Δ͕ɺRust͸ԿΛ͍ͯ͠Δͷ͔ɻ • V8͕Ͱ͖Δͷ͸Sandbox಺ͰECMAScriptͷղऍͰɺͦΕҎ֎ͷωοτϫʔΫ΍ϑΝΠϧૢ࡞ͳͲ͸ RustଆͰߦ͏ • ωοτϫʔΫ΍ϑΝΠϧૢ࡞͸ηΩϡϦςΟͷ੍ݶΛड͚ɺ࣮ߦ࣌ʹڐՄ͓ͯ͘͠ඞཁ͕͋Δ

    • V8ͱRust͸͋Β͔͡Ίఆٛͨؔ͠਺Ͱ૬ޓʹ΍ΓͱΓ͢Δ͜ͱ͕Ͱ͖Δ • σʔλ͸ϙΠϯλʔΛ࢖͍ίϐʔ͸͠ͳ͍ʢจࣈྻ΍਺஋Ͱ͸ͳ͍ͷͰύϑΥʔϚϯεͷ໰୊͕͓͖ͳ ͍ʣ • ॳظ͸RustͰͳ͘GoͰ࣮૷͞Ε͍͕ͯͨGoͱV8ͷ̎ॏGCͷ໰୊͔ΒRustʹஔ͖׵͑ΒΕͨ 8
  9. Fukuoka.ts #3 9 ΠϯλʔϑΣʔε͸OpsͱResourceͷ̎छྨ https://www.youtube.com/watch?v=1b7FoBwxc7E

  10. Fukuoka.ts #3 Denoͷϓϩηε Deno͸Rustϓϩηεͱͯ͠ىಈͯ͠ɺdenoͷϝΠϯεϨουͱV8ͷWorkerεϨουͱ TokioͷεϨουϓʔϧʹΑΓߏ੒͞ΕΔɻ • tsc·ͨ͸swcʹΑͬͯґଘղܾͱϦϞʔτϑΝΠϧͷμ΢ϯϩʔυΛߦ͍γϯάϧϑΝ ΠϧԽ • ͦͷjs΍wasm͕V8ͷதͰ࣮ߦ͞ΕΔ

    • V8ʹͳ͍ؔ਺͸RustଆΛݺͼग़͢ • Event Loopͷcore෦෼͸RustଆͰ࣮૷͞ΕTokio͸εέδϡʔϥʔͱͯ͠εϨουΛ ؅ཧ͢Δ 10
  11. Fukuoka.ts #3 11 https://deno.land/manual@v1.13.1/contributing/architecture Manualʹ͋ͬͨArchitectureਤʢࠓ͸libdeno͕rusty_v8ʹͳ͍ͬͯΔ͔Βݹ͍͔΋ʣ

  12. Fukuoka.ts #3 Denoͷ֦ு V8͸WebAssembly(wasm) ΋࣮ߦͰ͖ΔͨΊɺwasmରԠ ͷͲΜͳݴޠͰ΋֦ு͕ՄೳͰ ͋Δɻ·ͨɺ࠷ۙಋೖ͞Εͨ dlopen ͰμΠφϛοΫϩʔυ ʹΑΔ֦ு͕Ͱ͖ΔΑ͏ʹͳͬ

    ͍ͯΔ(v1.13)ɻ 12
  13. Fukuoka.ts #3 Demo: rust(wasm-pack)Ͱdeno֦ு 13

  14. Fukuoka.ts #3 14 ςϯϓϨʔτͰ͸wasmͷgreetؔ਺Ͱjsͷalertؔ਺ʹbind͢ΔΑ͏ʹ

  15. Fukuoka.ts #3 ·ͱΊ • Deno͸node.jsͰͷܦݧ͔ΒV8ͱͷ݁߹ʹந৅ϨΠϠʔΛ࡞Δ͜ͱͰ҆શʹ͍ͯ͠Δ • V8Ҏ֎ʹ΋tokio΍tscɺswcͳͲ3rd Party͕ଟ͘࢖ΘΕҰൠతͳݴޠϥϯλΠϜͰ͸ෳࡶ Ͱ͋Δ͕ίϯϙʔωϯτΛࡉ͔͘෼ׂ͢Δ͜ͱͰӨڹΛখ͍ͯ͘͞͠Δ •

    ϑΝΠϧૢ࡞΍ωοτϫʔΫͳͲV8ͷείʔϓ֎͸rust͕୲͍ͬͯͯϗϫΠτϦετͷη ΩϡϦςΟͰ҆શΛ୲อ͍ͯ͠Δ • V8ͱRustͷؒʹσʔλίϐʔ͸ͳͦ͘ͷଞͷύϑΥʔϚϯεʹ஫ྗͰ͖ΔΑ͏ʹ͍ͯ͠Δ 15
  16. Fukuoka.ts #3 16 Thank You, We’re Hiring! ʮϖύϘΩϟϦΞ࠾༻ʯݕࡧ