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

[BUGFIX release] Simplify mixin application #19082

Merged
merged 1 commit into from
Aug 10, 2020
Merged

[BUGFIX release] Simplify mixin application #19082

merged 1 commit into from
Aug 10, 2020

Conversation

pzuraq
Copy link
Contributor

@pzuraq pzuraq commented Aug 7, 2020

Simplifies mixin application in a number of ways:

  • Ensures that we only access meta once for a given object when
    applying mixins
  • Ensures that we only peekDescriptors once for a given descriptor
  • Minimizes the number of if/else branches and defaulting in general
  • Breaks apart defineProperty so that we can do less work per
    definition when mixing in mixins, since we know more about what
    possible operations will occur.
  • Removes extra brand checks from defineProperty (Array.isArray) so
    we don't penalize every defineProperty for doing that.
  • Only revalidate observers once per mixin application.
  • Only brand check didDefineProperty once per mixin application.
  • Replace for..in loops with Object.keys since we only care about
    own properties.
  • Only loop once in extractAccessors.
  • Combine observer and listener meta into a single object so we only
    need to do one lookup. In most cases, this is undefined in modern
    applications, so no extra memory cost.
  • Simplify CP descriptor property lookups (remove duplicate functions).

Benchmark results:

artifact-60.pdf

import('./decorator').Decorator,
import('./decorator').ComputedDescriptor | boolean
> = new WeakMap();
const DECORATOR_DESCRIPTOR_MAP: WeakMap<Function, unknown | boolean> = new WeakMap();
Copy link
Contributor

Choose a reason for hiding this comment

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

unknown | boolean is the same as unknown

@rwjblue rwjblue requested a review from krisselden August 8, 2020 14:01
Simplifies mixin application in a number of ways:

- Ensures that we only access `meta` once for a given object when
  applying mixins
- Ensures that we only `peekDescriptors` once for a given descriptor
- Minimizes the number of if/else branches and defaulting in general
- Breaks apart `defineProperty` so that we can do less work per
  definition when mixing in mixins, since we know more about what
  possible operations will occur.
- Removes extra brand checks from `defineProperty` (Array.isArray) so
  we don't penalize every defineProperty for doing that.
- Only revalidate observers once per mixin application.
- Only brand check `didDefineProperty` once per mixin application.
- Replace `for..in` loops with `Object.keys` since we only care about
  own properties.
- Only loop once in `extractAccessors`.
- Combine observer and listener meta into a single object so we only
  need to do one lookup. In most cases, this is undefined in modern
  applications, so no extra memory cost.
- Simplify CP descriptor property lookups (remove duplicate functions).
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.

3 participants