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

Reduce apply() calls to improve call times. #765

Merged
merged 1 commit into from
May 30, 2023

Conversation

jdmarshall
Copy link
Contributor

This brings opossum.fire() roughly in line with hystrixjs.execute()

Reduces fire() call time by about 50%, and fallback call time by 30%

fire() x 134,900 ops/sec ±42.25% (21 runs sampled)
fire() error x 68,030 ops/sec ±31.60% (8 runs sampled)

fire() x 286,626 ops/sec ±28.73% (56 runs sampled)
fire() error x 99,637 ops/sec ±2.48% (10 runs sampled)

Reduces fire() call time by about 50%, and fallback call time by 30%

fire() x 134,900 ops/sec ±42.25% (21 runs sampled)
fire() error x 68,030 ops/sec ±31.60% (8 runs sampled)

fire() x 286,626 ops/sec ±28.73% (56 runs sampled)
fire() error x 99,637 ops/sec ±2.48% (10 runs sampled)
@@ -582,7 +580,8 @@ class CircuitBreaker extends EventEmitter {
const err = buildError('The circuit has been shutdown.', 'ESHUTDOWN');
return Promise.reject(err);
}
const args = Array.prototype.slice.call(rest);

const args = rest.slice();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rest arguments become [] when no arguments provided, so Array.prototype.slice is guarding nothing.

Copy link
Member

Choose a reason for hiding this comment

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

I think i remember why Array.prototype.slice was used. originally we used the arguments parameter which array like but not an array, so that whole thing was needed. when it was convereted to rest params, we just forgot to take it out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds about right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly I was commenting to say "I thought about undefined"

@jdmarshall
Copy link
Contributor Author

This addresses questions asked and answered in #758

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5095893721

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.003%) to 98.233%

Totals Coverage Status
Change from base Build 5081372639: -0.003%
Covered Lines: 354
Relevant Lines: 355

💛 - Coveralls

@lholmquist lholmquist requested a review from lance May 30, 2023 13:52
Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

/lgtm

@lholmquist lholmquist merged commit 8d559e4 into nodeshift:main May 30, 2023
@jdmarshall
Copy link
Contributor Author

Talking it out with some coworkers this morning, I mentioned I was a little surprised by how effective this PR was. I was expecting about 2/3rds of this improvement at the outside.

What I'm thinking is that the apply/rest performance discrepancy may have increased in Node 16, when V8 changed how it handled function arguments (specifically to speed up calls with the 'wrong' number of args). I looked at this when rest parameters were first introduced and while it was helpful, it wasn't 'drop everything' level of performance gap.

At a guess, I'm thinking the average overhead for regular calls went down compared to apply(), anonymous functions versus arrow functions, functions that use arguments, or some combination of the three.

@lholmquist
Copy link
Member

just released 8.0.1

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.

4 participants