Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide JSON serialized profiles #69

Open
jkrems opened this issue Jan 28, 2022 · 2 comments
Open

Provide JSON serialized profiles #69

jkrems opened this issue Jan 28, 2022 · 2 comments

Comments

@jkrems
Copy link

jkrems commented Jan 28, 2022

From the current examples:

const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });
const start = performance.now();
for (let i = 0; i < 1000000; i++) {
     doWork();
}
const duration = performance.now() - start;
const trace = await profiler.stop();
const traceJson = JSON.stringify({
  duration,
  trace,
});
sendTrace(traceJson);

While serializing the JSON might be okay for small profiles, it seems risky to encourage it as a general solution. Would it be better to provide the profile as serialized JSON already, potentially removing some blocking work from the main thread? It's not unlikely that those data structures wouldn't have to exist in the JS heap at any point in time.

@paulirish
Copy link

Thinking out loud, one could transfer the trace to a worker and serialize+beacon it there. Especially seems preferred if you want to add in a CompressionStream.

@jkrems
Copy link
Author

jkrems commented Feb 21, 2022

Since you mentioned CompressionStream (and this is WICG, not raw JS), maybe the result of calling profiler.stop() could follow Response precedent and offer both .json(): Promise<TraceData> and .stream() (like res.body, for direct use in a compression stream)? Having the data in the main thread JS heap + transferring could still be a noticeable cost but having .stream() seems to also allow easy transfer to a separate worker thread.

@Qard Qard mentioned this issue Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants