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

Improve stripProtoKeys performance, especially for TypedArray #9742

Merged
merged 1 commit into from Jun 13, 2022

Conversation

mjgp2
Copy link
Contributor

@mjgp2 mjgp2 commented Jun 7, 2022

Fixes 9708

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: 9708

What is the new behavior?

Does not waste cycles on iterating through typed arrays, or allocating keys arrays.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@mjgp2 mjgp2 force-pushed the stripProtoKeys-performance branch 2 times, most recently from fcd6fc1 to 2cca33a Compare June 7, 2022 11:34
@mjgp2 mjgp2 force-pushed the stripProtoKeys-performance branch 3 times, most recently from b2ea591 to 62d2f6d Compare June 7, 2022 11:52
@coveralls
Copy link

coveralls commented Jun 7, 2022

Pull Request Test Coverage Report for Build 29996fd0-df63-435a-96f3-db353cf09d52

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 94.112%

Totals Coverage Status
Change from base Build 3833bc5d-ac71-4db9-b614-33791ff96fb8: 0.005%
Covered Lines: 5786
Relevant Lines: 6148

💛 - Coveralls

Copy link
Member

@micalevisk micalevisk left a comment

Choose a reason for hiding this comment

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

can you please run npm run format

@@ -190,12 +191,20 @@ export class ValidationPipe implements PipeTransform<any> {
return isNil(value) ? {} : value;
}

protected stripProtoKeys(value: Record<string, any>) {
protected stripProtoKeys(value: any) {
if (value == null || typeof value !== 'object' || types.isTypedArray(value)) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess

Suggested change
if (value == null || typeof value !== 'object' || types.isTypedArray(value)) {
if (!value || !isObject(value) || types.isTypedArray(value)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This causes a typescript compilation error because isObject is a type guard and Property '__proto__' does not exist on type 'object'

I would suggest just leaving as-is?

Copy link
Member

Choose a reason for hiding this comment

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

oh, it's fine then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, I think this should be good to merge then 🤞

@mjgp2 mjgp2 force-pushed the stripProtoKeys-performance branch from 62d2f6d to f445f23 Compare June 10, 2022 07:34
@kamilmysliwiec kamilmysliwiec merged commit ade844e into nestjs:master Jun 13, 2022
@kamilmysliwiec
Copy link
Member

LGTM

@mjgp2
Copy link
Contributor Author

mjgp2 commented Jun 13, 2022

Thanks all, appreciate your work 👍

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.

None yet

4 participants