jupyter_server
jupyter_server copied to clipboard
Enabling javascript self-profiling
Problem
Jupyter web frontends may want to enable js self-profiling (spec) in order to:
- add tests ensuring preventing regressions such as layout trashing (e.g. https://github.com/jupyterlab/lumino/pull/432)
- allow users to generate and share performance profiles for developers to address (without requiring users to learn how to use the in-browser profiler)
- run JS and browser event (style computation, layout, paint) benchmarks on different configurations easily
Enabling self-profiling requires the backend to set Document-Policy: js-profiling in HTTP response header. The purpose of this header is to prevent the overhead of starting a profiler on every website which gets opened.
Proposed Solution
Add a command-line flag which would result in set the required header. Since the feature is not standard, it could have an experimental prefix e.g. --experimental-allow-js-self-profiling.
Is that something that we are happy to have in jupyter-server, or should it be implemented down the stack, e.g. in jupyterlab-server or an extension?
Additional context
This is currently a draft API implemented in Chrome, and is not standard and there is no consensus on adopting it for now (see https://github.com/mozilla/standards-positions/issues/477).
I think you can write a server extension that conditionally adds the headers. In the base authed handler, it looks in the settings for any headers to add:
https://github.com/jupyter-server/jupyter_server/blob/1957aa0416c8467961198fa2dd6f930aca106f85/jupyter_server/base/handlers.py#L91
If the extension is able to add to this setting, it should be able to do what you want, I think :)
Thanks for the hint! Closing, as this was implemented in jupyterlab-ui-profiler without need for a change in jupyter-server. If anyone is interested in code, look at these lines.