Skip to content

check: return instead of throw internally #4584

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

Closed
wants to merge 3 commits into from
Closed

check: return instead of throw internally #4584

wants to merge 3 commits into from

Conversation

wh0
Copy link

@wh0 wh0 commented Jun 17, 2015

Profiling our teams app showed that a lot of time was spent creating errors for the check package, which I assume creates a stack trace each time. For every Match.Optional or Match.OneOf, it would have to create a stack trace for the one choice that failed.

Anyway, this PR modifies check's internal implementation to use more return instead of throw, so as not to construct so many error objects. It shouldn't change the external API of check or Match.Where.

This sped up one of our app's benchmarks, which called Collection::find many times (find internally uses check to validate its second parameter).

@@ -145,33 +139,41 @@ var typeofChecks = [
[undefined, "undefined"]
];

var checkSubtree = function (value, pattern) {
// Return `false` if it matches. Otherwise, return an object with a `message` and a `path` field.
var testSubtree = function (value, pattern) {
Copy link
Author

Choose a reason for hiding this comment

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

This doesn't correspond to test the way checkSubtree corresponded to check.

@apollo-cla
Copy link

@wh0: Before we can merge your pull request, you'll need to sign the Meteor Contributor Agreement: https://contribute.meteor.com/

@jperl
Copy link
Contributor

jperl commented Jun 19, 2015

❤️

if (value === null)
throw new Match.Error("Expected object, got null");
return {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these if statements have become multiple lines, let's wrap the body in brackets.

@stubailo
Copy link
Contributor

@wh0 still waiting on the for loop change! Excited to get this change in.

@stubailo stubailo self-assigned this Jun 29, 2015
@mitar
Copy link
Contributor

mitar commented Jun 29, 2015

Yea!

@wh0 wh0 closed this Sep 17, 2015
@wh0 wh0 deleted the check-nothrow branch September 17, 2015 22:52
@mitar
Copy link
Contributor

mitar commented Sep 17, 2015

Why closing?

@wh0
Copy link
Author

wh0 commented Sep 17, 2015

whoa, I accidentally deleted my branch

@wh0 wh0 restored the check-nothrow branch September 17, 2015 23:00
@wh0 wh0 reopened this Sep 17, 2015
@stubailo
Copy link
Contributor

Lol, I should merge this

@mitar
Copy link
Contributor

mitar commented Sep 17, 2015

Yes you should. :-)

@stubailo
Copy link
Contributor

Merged: 4f79c60

@wh0, you should set up an email address in Git so that GitHub can track your commits! Otherwise it will be super hard to trace them back to you if something comes up like a question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants