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

Replace Assert with Return #1204

Conversation

waynerobinson
Copy link
Contributor

@waynerobinson waynerobinson commented Sep 29, 2022

Node's native assert() can be very heavy, especially in a large project with a source map as it creates a full stack trace on failure.

In practice, we were seeing negative responses to model.find() taking up to 2 seconds to resolve.

Most assertions in this library are either for config or use Koa's assert method, which uses a considerably lighter code-path.

Replacing with if (!stored) { return } is an effectively free operation and solved our performance issues on negative responses.

Node's native `assert()` can be very heavy, especially in a large project
with a source map as it creates a full stack trace on failure.

In practice, we were seeing negative responses to model.find() taking
up to 2 seconds to resolve.

Most assertions in this library are either for config or use Koa's `assert`
method, which uses a considerably lighter code-path.

Replacing with if `(!stored) { return }` is an effectively free
operation.
Copy link
Owner

@panva panva left a comment

Choose a reason for hiding this comment

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

Move it out of the try block please.

@waynerobinson
Copy link
Contributor Author

Moved. 😀

@panva
Copy link
Owner

panva commented Oct 5, 2022

I'll go through the rest of the hot path asserts and replace them. Since i'm not able to push to your upstream I'll do the rest of the work in #1205 where i've kept you as co-author.

@waynerobinson
Copy link
Contributor Author

No problem, thanks for that. It's a big library and I'm a little unsure what should and shouldn't be altered. 😅

@panva panva force-pushed the main branch 4 times, most recently from 18906ce to e969c39 Compare October 18, 2022 17:44
@panva panva closed this in 1f77781 Dec 3, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants