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

perf(reactivity): improve reactive effect memory usage #4001

Merged
merged 4 commits into from
Jun 24, 2021

Conversation

yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Jun 24, 2021

Based on #2345 , but with smaller API change

  • Use class implementation for ReactiveEffect
  • Switch internal creation of effects to use the class constructor
  • Avoid options object allocation
  • Avoid creating bound effect runner function (used in schedulers) when not necessary. Only component update effects will need to create a bound copy of the runner.

Screen Shot 2021-06-24 at 5 29 31 PM

Consumes ~17% less memory compared to last commit (which already improved the memory usage a bit) when creating computed/watch/watchEffect (image showing benchmark of creating 10k each).

Introduces a very minor breaking change: the scheduler option passed to effect no longer receives the runner function. Instead, simply call the reference of the returned runner:

const run = effect(() => {}, {
  scheduler: () => {
    run()
  }
})

- Use class implementation for ReactiveEffect
- Avoid options object allocation
- Lazy initailize bound runner function only when necessary

Benchmark showing around ~17% memory saving when creating computed and
watcher instances.
- introduces a minor breaking change where the scheduler no
longer receives the bound runner
@yyx990803 yyx990803 merged commit 34a6041 into 3.2 Jun 24, 2021
@yyx990803 yyx990803 deleted the improve-effect-memory branch June 24, 2021 21:44
yyx990803 added a commit that referenced this pull request Jul 1, 2021
Based on #2345 , but with smaller API change

- Use class implementation for `ReactiveEffect`
- Switch internal creation of effects to use the class constructor
- Avoid options object allocation
- Avoid creating bound effect runner function (used in schedulers) when not necessary.
- Consumes ~17% less memory compared to last commit
- Introduces a very minor breaking change: the `scheduler` option passed to `effect` no longer receives the runner function.
yyx990803 added a commit that referenced this pull request Jul 5, 2021
Based on #2345 , but with smaller API change

- Use class implementation for `ReactiveEffect`
- Switch internal creation of effects to use the class constructor
- Avoid options object allocation
- Avoid creating bound effect runner function (used in schedulers) when not necessary.
- Consumes ~17% less memory compared to last commit
- Introduces a very minor breaking change: the `scheduler` option passed to `effect` no longer receives the runner function.
yyx990803 added a commit that referenced this pull request Jul 6, 2021
Based on #2345 , but with smaller API change

- Use class implementation for `ReactiveEffect`
- Switch internal creation of effects to use the class constructor
- Avoid options object allocation
- Avoid creating bound effect runner function (used in schedulers) when not necessary.
- Consumes ~17% less memory compared to last commit
- Introduces a very minor breaking change: the `scheduler` option passed to `effect` no longer receives the runner function.
yyx990803 added a commit that referenced this pull request Jul 15, 2021
Based on #2345 , but with smaller API change

- Use class implementation for `ReactiveEffect`
- Switch internal creation of effects to use the class constructor
- Avoid options object allocation
- Avoid creating bound effect runner function (used in schedulers) when not necessary.
- Consumes ~17% less memory compared to last commit
- Introduces a very minor breaking change: the `scheduler` option passed to `effect` no longer receives the runner function.
yyx990803 added a commit that referenced this pull request Jul 16, 2021
Based on #2345 , but with smaller API change

- Use class implementation for `ReactiveEffect`
- Switch internal creation of effects to use the class constructor
- Avoid options object allocation
- Avoid creating bound effect runner function (used in schedulers) when not necessary.
- Consumes ~17% less memory compared to last commit
- Introduces a very minor breaking change: the `scheduler` option passed to `effect` no longer receives the runner function.
yangmingshan added a commit to vue-mini/vue-mini that referenced this pull request Sep 19, 2021
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.

1 participant