Slide 1

Slide 1 text

Fukuoka.ts #3 TS How deno works as TS runtime Tomohisa Oda — GMO Pepabo, Inc. / Aug 23th 2021

Slide 2

Slide 2 text

Fukuoka.ts #3 linyows / Tomohisa Oda GMO Pepabo, Inc.: Senior Engineering Lead Blog: https://tomohisaoda.com 2

Slide 3

Slide 3 text

Fukuoka.ts #3 3 Private Projects ΞϓϦέʔγϣϯࣗ਎͕ϦϙδτϦ͔ Β࠷৽ͷίʔυΛݕ஌ͯࣗ͠ಈͰσϓϩ ΠͱσϦόϦʔΛߦ͏πʔϧ linuxͷuser໊લղܾΛGitHubͷ Teamϝϯόʔ΍ϦϙδτϦͷΞΫηε ݖݶऀ͔Βߦ͏πʔϧ ϝʔϧૹ৴༻ͷಁաܕSMTPϓϩΩγͰ ϦΫΤετͱϨεϙϯεΛϩά΍σʔλ ϕʔεʹग़ྗ͢Δ͜ͱ͕Ͱ͖Δ New!!

Slide 4

Slide 4 text

Fukuoka.ts #3 ͓࿳ͼɿDenoਂງΓ👉Denoͷ࢓૊Έ 4

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Fukuoka.ts #3 7 https://choubey.gitbook.io/internals-of-deno/architecture/overall-architecture

Slide 8

Slide 8 text

Fukuoka.ts #3 V8ͱRustͷ໾ׂ෼୲ deno͸༷ʑͳίϯϙʔωϯτ͕͋ΓଞݴޠͰߏ੒͞Ε͍ͯΔɻ௒ઈࡶʹ͍͏ͱɺdeno͸V8ͷϥούʔ Ͱ͋Δ͕ɺRust͸ԿΛ͍ͯ͠Δͷ͔ɻ • V8͕Ͱ͖Δͷ͸Sandbox಺ͰECMAScriptͷղऍͰɺͦΕҎ֎ͷωοτϫʔΫ΍ϑΝΠϧૢ࡞ͳͲ͸ RustଆͰߦ͏ • ωοτϫʔΫ΍ϑΝΠϧૢ࡞͸ηΩϡϦςΟͷ੍ݶΛड͚ɺ࣮ߦ࣌ʹڐՄ͓ͯ͘͠ඞཁ͕͋Δ • V8ͱRust͸͋Β͔͡Ίఆٛͨؔ͠਺Ͱ૬ޓʹ΍ΓͱΓ͢Δ͜ͱ͕Ͱ͖Δ • σʔλ͸ϙΠϯλʔΛ࢖͍ίϐʔ͸͠ͳ͍ʢจࣈྻ΍਺஋Ͱ͸ͳ͍ͷͰύϑΥʔϚϯεͷ໰୊͕͓͖ͳ ͍ʣ • ॳظ͸RustͰͳ͘GoͰ࣮૷͞Ε͍͕ͯͨGoͱV8ͷ̎ॏGCͷ໰୊͔ΒRustʹஔ͖׵͑ΒΕͨ 8

Slide 9

Slide 9 text

Fukuoka.ts #3 9 ΠϯλʔϑΣʔε͸OpsͱResourceͷ̎छྨ https://www.youtube.com/watch?v=1b7FoBwxc7E

Slide 10

Slide 10 text

Fukuoka.ts #3 Denoͷϓϩηε Deno͸Rustϓϩηεͱͯ͠ىಈͯ͠ɺdenoͷϝΠϯεϨουͱV8ͷWorkerεϨουͱ TokioͷεϨουϓʔϧʹΑΓߏ੒͞ΕΔɻ • tsc·ͨ͸swcʹΑͬͯґଘղܾͱϦϞʔτϑΝΠϧͷμ΢ϯϩʔυΛߦ͍γϯάϧϑΝ ΠϧԽ • ͦͷjs΍wasm͕V8ͷதͰ࣮ߦ͞ΕΔ • V8ʹͳ͍ؔ਺͸RustଆΛݺͼग़͢ • Event Loopͷcore෦෼͸RustଆͰ࣮૷͞ΕTokio͸εέδϡʔϥʔͱͯ͠εϨουΛ ؅ཧ͢Δ 10

Slide 11

Slide 11 text

Fukuoka.ts #3 11 https://deno.land/[email protected]/contributing/architecture Manualʹ͋ͬͨArchitectureਤʢࠓ͸libdeno͕rusty_v8ʹͳ͍ͬͯΔ͔Βݹ͍͔΋ʣ

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Fukuoka.ts #3 Demo: rust(wasm-pack)Ͱdeno֦ு 13

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Fukuoka.ts #3 ·ͱΊ • Deno͸node.jsͰͷܦݧ͔ΒV8ͱͷ݁߹ʹந৅ϨΠϠʔΛ࡞Δ͜ͱͰ҆શʹ͍ͯ͠Δ • V8Ҏ֎ʹ΋tokio΍tscɺswcͳͲ3rd Party͕ଟ͘࢖ΘΕҰൠతͳݴޠϥϯλΠϜͰ͸ෳࡶ Ͱ͋Δ͕ίϯϙʔωϯτΛࡉ͔͘෼ׂ͢Δ͜ͱͰӨڹΛখ͍ͯ͘͞͠Δ • ϑΝΠϧૢ࡞΍ωοτϫʔΫͳͲV8ͷείʔϓ֎͸rust͕୲͍ͬͯͯϗϫΠτϦετͷη ΩϡϦςΟͰ҆શΛ୲อ͍ͯ͠Δ • V8ͱRustͷؒʹσʔλίϐʔ͸ͳͦ͘ͷଞͷύϑΥʔϚϯεʹ஫ྗͰ͖ΔΑ͏ʹ͍ͯ͠Δ 15

Slide 16

Slide 16 text

Fukuoka.ts #3 16 Thank You, We’re Hiring! ʮϖύϘΩϟϦΞ࠾༻ʯݕࡧ