Off the Main Thread ͱ
• Main Thread ͰͷॲཧΛۃྗখ͘͞Ͱ͖ΔΑ͏ʹ͍ͯ͠
͜͏ͱ͍͏ࢼΈʢ·ͩԿ͔͕݁ग़ͯΔΘ͚Ͱͳ͍ʣ
• Main Threadͷॲཧ͕ॏ͘ͳΔͱUI JankͱݺΕΔʰΧ
ΫπΩɾΨλπΩɾҰݟಈ͍ͯͳ͍͔ͷΑ͏ʹݟ͑Δো
ʱ͕ൃੜ͢Δ
• Main Thread ͔Β Worker Thread Λ͏·͑͘ΔΑ͏
ʹɺͱ͍͏ͷ͕τϐοΫͷҰͭɻ
Slide 43
Slide 43 text
Off the Main Thread
• ϒϥβ͔Βmain thread͕ࢥ͍ͱೖྗͰ͖
Δͷ͕͘ͳͬͨΓɺεΫϩʔϧ͕Ψλ͍ͭ
ͨΓ͢Δ
https://docs.google.com/presentation/d/1OBij2sz6gNU-VCrNz7REvJ4piiM21YZnVCUnl6MjUas/
edit#slide=id.g372bf772fc_0_55
Make Worker Better Again
• WebWorkerͰλεΫฒྻԽͰ͖ͯεέ
δϡʔϦϯά͕ʹͳΔɻ
• աڈʹJS Schedulerͷproposalɻ
Slide 50
Slide 50 text
Make Worker Better Again
• ͦͦ JavaScript ্Ͱ࣮ࢪ͢ΔͷʹҰ൪͋ͬ
ͨϚϧνεϨουϞσϧԿͳͷ͔ʁ
• SharedArrayBuffer͏ͷ͕͍͍ͷʁ
• WebKitͷํConcurrent JavaScriptͷఏҊ
͍ͯͨ͠ɻ
Slide 51
Slide 51 text
Make Worker Better Again
• WebKitͷํ͕JSͰฒߦॲཧ͢Δͱ͖ͷํ๏ɺಛʹ
SharedArrayBufferΛͬͨϞσϧΛৄղ
• SharedArrayBuffer͏ͷ͕͍͍ͷʁ
• WebKitͷํConcurrent JavaScriptͷఏҊͯ͠
͍ͨɻ
Slide 52
Slide 52 text
Make Worker Better Again
• Tasklets API
• Task ୯ҐͰখ͘͞background taskͱ࣮ͯ͠
ߦͤ͞ΔΈ
https://nhiroki.jp/2017/12/10/javascript-parallel-processing#6-worklet
Slide 53
Slide 53 text
Make Worker Better Again
• StreamͰWorkerܦ༝ͰσʔλՃ
• Main͔ΒTransform Workerʹྲྀ͢
Slide 54
Slide 54 text
Make Worker Better Again
// Main
const worker = new Worker('transcode.js');
worker.onmessage = event => {
const transcoder = event.data;
await fetch('bunny.vp10')
.pipeThrough(transcoder)
.pipeTo(videoSink);
};
// Worker ଆ
importScripts('vp10decode.js', 'mp4encode.js');
const transcoder = new TransformStream({
transform(chunk, controller) {
const decoded = vp10decode(chunk);
controller.enqueue(mp4encode(decoded));
}
});
postMessage(transcoder, [transcoder]);
Slide 55
Slide 55 text
Make Worker Better Again
• blöcks
• syntax parse, serialize ΛผεϨουͰͰ͖Δ
Α͏ʹ͢ΔͨΊͷ৽͍͠ఏҊ
// {| … |} ͰผWorker thread Ͱ parse ͤ͞Δ
const result = await worker({|
const res = await fetch("people.json");
const json = await res.json();
return json[2].firstName;
|});
Slide 56
Slide 56 text
Off the main thread·ͱΊ
• main threadʹෛՙ͕͔͔Βͳ͍Α͏ʹlighthouseͰϝτϦΫεΛऔΕ
ΔΑ͏ʹ͍ͯ͠Δ
• Performance ObserverͰLongTaskΛݕ͢ΔAPI༷ࡦఆத
• Worker APIΛͬͱ͍͘͢͢ΔͨΊͷٞΛ࣮ࢪத
• SchedulerͲ͏͢Δ͔
• σʔλڞ༗Ͳ͏͢Δ͔
• Tasklets, Transferable Stream, blöcks etc etc
ࢀߟࢿྉ
• Σϒϒϥβͷ off-the-main-thread API ͷ https://nhiroki.jp/2018/05/07/off-the-main-
thread-api
• off the main thread with workers https://speakerdeck.com/kosamari/off-the-main-thread-with-
workers
• improving the developer experience for doing work off the main thread http://bit.ly/blinkon9-
omt
• web application 2018 from performance perspective https://speakerdeck.com/
yosuke_furukawa/web-application-2018-from-performance-perspective
• Speed Focus for 2018 https://docs.google.com/presentation/d/1OBij2sz6gNU-
VCrNz7REvJ4piiM21YZnVCUnl6MjUas/edit#slide=id.g372bf772fc_0_55
• high performance web sites https://www.amazon.co.jp/dp/B0028N4WHY/
• high performance browser networking https://www.amazon.co.jp/dp/B00FM0OC4S/