dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.56k stars 4.54k forks source link

WASM startup time optimization tracking issue #63809

Open kg opened 2 years ago

kg commented 2 years ago

This issue tracks various parts of WebAssembly startup performance that need investigation and describes some potential solutions.

Current list of items from examining a small application (raytracer) as of 2024-03:

Profiles of startup for the blazor 8.0 samples: interpreted, high precision, firefox: https://profiler.firefox.com/public/4tgsv0kh4xvgrckp4w9dcqvyen8x1ftnm8df5d8/calltree/?globalTrackOrder=0&invertCallstack&thread=0&transforms=cr-combined-16-43063~cr-combined-13-43060~cr-combined-24-43071~cr-combined-15-43062~f-combined-0cjnxyb&v=10 aot, low precision, chrome: https://profiler.firefox.com/public/kbd0e1vks074a5af67g2ntzwvwbx20mhgag5rvr/calltree/?globalTrackOrder=0w3&hiddenGlobalTracks=023&hiddenLocalTracksByPid=37252-0w4~29452-0ws~1948-0w4~0-0&invertCallstack&thread=6&timelineType=category&transforms=df-31~mf-193~mf-265~mf-191~mf-190~mf-294~df-1&v=10

Profiles of startup for @maraf 's Money application on 9.0 preview 2: interpreted, high precision, firefox: https://share.firefox.dev/3TRtKkM aot, low precision, chrome: https://share.firefox.dev/3IQUT0P

Archived work items from the past:

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 2 years ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

Issue Details
This issue tracks various parts of startup performance that need investigation and potential improvement and describes some potential solutions. - [ ] Redundant startup i/o: We load lots of data at startup every time (IL, assembly metadata, timezone data, etc) and then load it into the heap. This involves multiple copies and is generally a waste of time. - [ ] Interpreter code generation: We spend a bunch of time generating interpreter IR from managed IL and in many cases that code runs once. We could optimize this out by pre-generating the IR and shipping it instead of IL. - [ ] Native static constructors and init code runs at startup and we could do this at build time. See https://github.com/emscripten-core/emscripten/pull/16011, recently added to emscripten. - [ ] Our init code and managed static constructors also could largely or entirely be run at build time, built on top of the solution for native. While we would need to do work to wire up things like JS handles and ensure we exempt static cctors that need to run after build, it's likely that we could optimize a lot of this out as well. Part of the cost of cctors is due to the interpreter having to do code gen (see above), because many cctors are huge.
Author: kg
Assignees: -
Labels: `arch-wasm`, `untriaged`, `tracking`
Milestone: -
pavelsavara commented 2 years ago

Could we store the IR-form (with a hash) into some browser cache for the next startup ?

SamMonoRT commented 1 year ago

cc @fanyang-mono for the first item.

kg commented 11 months ago

Startup I/O is covered by the memory snapshot, I believe? IR caching could be too if we move the snapshot later in startup.