Skip to content

Implement profiler for lifecycle events. - #868

Merged
internettrans merged 5 commits into
6.0from
profiler-1
Sep 15, 2021
Merged

internettrans merged 5 commits into
6.0from
profiler-1

Conversation

@internettrans

@internettrans internettrans commented Sep 14, 2021 •

Copy link
Copy Markdown
Member

This sets up the approach for profiling and then implements it for application and parcel lifecycles. To start with, I've just added the profiler to the single-spa dev build, not prod build. I know that React has a production profiler build but didn't think the performance difference between the dev and prod build to be large enough to justify adding a bunch of new bundles to the tarball published to npm.

I'm most interested in feedback on the profiler api and what data we track. My idea is that single-spa-inspector will call getProfilerData and then show some of the data in the browser extension and maybe even provide a way to download the profiler data to a CSV file or something.

Future PRs will add profiler events within the reroute function to track which parts of the rerouting takes longest.

@frehner frehner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor comments.

Comment thread src/lifecycles/bootstrap.js Outdated
}

if (__PROFILE__) {
startTime = Date.now();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to consider using performance.now() instead? https://developer.mozilla.org/en-US/docs/Web/API/Performance/now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't know about performance.now(). The one potential downside is you lose absolute timestamps (2021-09-14 00:00:00) in favor of timestamps that are relative to the time origin. But that might even be better, it's not clear that it's really a downside. So I'll switch them over.

Comment thread src/devtools/profiler.js
Comment on lines +16 to +23
export function addProfileEntry(
type,
name,
kind,
start,
end,
operationSucceeded
) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting that you take these in as separate params (which require remembering the order), but in the end store them as object properties in the end. Would it be easier to just make this an object from the get-go?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did them as separate params with the idea being it would keep bundle size down. It's true that i later put them in an object, but my thought was that at least the property names are only in one place rather than in every place that adds a profile entry?

@frehner frehner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐽

@internettrans
internettrans merged commit b62a9ed into 6.0 Sep 15, 2021
@internettrans
internettrans deleted the profiler-1 branch September 15, 2021 18:59
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

Successfully merging this pull request may close these issues.

2 participants