vue-i18n icon indicating copy to clipboard operation
vue-i18n copied to clipboard

SSR Memory Leak

Open PanZeYong opened this issue 4 years ago • 5 comments
trafficstars

Module versions (please complete the following information):

  • vue:v2.4.1
  • vue-i18n:v8.24.2

Question

My Project is using Vue SSR, when tests stress by the ab tool, the memory increases all the time. But when I remove the vue-i18n and tests again, the memory does not increase. So I guess the vue-i18n exists ssr memory leak, what I want to ask that is there anyone has the same question and how to solve? Thanks.

PanZeYong avatar May 10 '21 07:05 PanZeYong

Thank you for your reporting!

We could not be sure of that without a reproducible procedure. Could you give us the minimum reproduction code or repo, please?

kazupon avatar May 10 '21 14:05 kazupon

We've seen a similar issue crop up in our application. Taking a heap dump of the application during a stress test there where a lot of watchers on the VueI18n object.

We've solved this by patching out the watchI18nData method after calling it once. I will see if I can post a minimal example later this week.

I'm not entirely sure if it has any other side effects that I'm not aware of. But as I understand the this._vm.watch('$data', () => {}) only needs to be created once.

The patch we used:

Vue.use(VueI18n);
const i18n = new VueI18n({
    messages: {},
});
// create one watcher at the start, and don't create any watchers at runtime.
i18n.watchI18nData();
i18n.watchI18nData = () => {};
Vue.mixin({
    i18n,
});

0Rick0 avatar Jul 27 '21 09:07 0Rick0

I've created a project that somewhat demonstrates the issue. https://github.com/0Rick0/i18n-bug-test

I'm not entirely sure what the difference is between our project and this one. In our project the memory usage increased a lot faster than in the sample created.

Let me know if you need more information :)

0Rick0 avatar Aug 04 '21 20:08 0Rick0

@0Rick0 Thank you for your repro repo!

It's very hard to make the memory leaks reproduce. We appreciate your information.

The memory leaks might be affected by the javascript code, and with Vue core code. So, please understand that it will take some time to fix.

kazupon avatar Aug 04 '21 23:08 kazupon

Not sure if it's the same issue, but there is a similar open issue: https://github.com/kazupon/vue-i18n/issues/589

I posted there another reproduction repo, if I can I love to help.

leonardlin avatar Oct 10 '21 15:10 leonardlin