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

Memory increase: Update from 4.0.2 to 4.1.0 #2236

Open
3 tasks done
fallemand opened this issue Sep 19, 2023 · 2 comments
Open
3 tasks done

Memory increase: Update from 4.0.2 to 4.1.0 #2236

fallemand opened this issue Sep 19, 2023 · 2 comments

Comments

@fallemand
Copy link

fallemand commented Sep 19, 2023

Version

4.1.0

Describe the bug

After upgrading from Vuex 4.0.2 to 4.1.0, our apps started skyrocketing in memory consumption until running out of memory.

image

The apps recovered just after the rollback was deployed, and we tried two times to be sure.

Reproduction

  • SSR Vue 3 app.
  • Vuex 4.1.0

Expected behavior

Memory levels should remain the same.

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@zcrumbo
Copy link

zcrumbo commented Dec 28, 2023

For what it's worth, I've also seen a memory leak for an SSR'd Vue app after moving from 4.0.2 to 4.1. Reverting solved the issue.
The heap dump indicated the store was getting persisted in memory for every page render, leading to a very fast OOM crash on the deployed container.

@zcrumbo
Copy link

zcrumbo commented Dec 29, 2023

It seems like this change is what is responsible - the closure seems to be retained on the SSR process

vuex/src/store-util.js

Lines 40 to 58 in d562224

const computedCache = {}
// create a new effect scope and create computed object inside it to avoid
// getters (computed) getting destroyed on component unmount.
const scope = effectScope(true)
scope.run(() => {
forEachValue(wrappedGetters, (fn, key) => {
// use computed to leverage its lazy-caching mechanism
// direct inline function use will lead to closure preserving oldState.
// using partial to return function with only arguments preserved in closure environment.
computedObj[key] = partial(fn, store)
computedCache[key] = computed(() => computedObj[key]())
Object.defineProperty(store.getters, key, {
get: () => computedCache[key].value,
enumerable: true // for local getters
})
})
})

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

No branches or pull requests

2 participants