Web developers want to understand how their webapps perform on real user devices, and they want to know which parts of their code are slow so they can target optimizations.
Currently, developers have to either profile their site in their own browser (not representative) or pepper their code with boilerplate timing statements (incomplete, doesn’t scale well). Facebook went one step further and implemented a sampling profiler with JavaScript and SharedArrayBuffers (which suffered from accuracy and performance drawbacks).
The existing approaches for debugging webapp slowdowns in the field are laborious, don’t have complete coverage, and have serious overheads. A native API for pages to profile their own JS execution would make debugging web performance a lot easier. Note that this API would only allow profiling the page’s JS execution, not any browser internals like DOM implementation. And since similar functionality can be polyfilled with JS, there should be no security or privacy concerns.
The collected profiles can be sent to analytics servers for aggregation and automatic analysis.
Rough ideas for an API:
window.performance.startProfiling(options) => Promise (resolves to a Profiler object)
Profiler.stopProfiling() => Promise
Profiler.cancelProfiling() => Promise
I wrote up a more detailed proposal and motivation here: https://github.com/vdjeric/js-self-profiling