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

v-t rendering is slower than $t() #1712

Open
5 tasks done
amurf opened this issue Jul 17, 2024 · 0 comments · May be fixed by #1713
Open
5 tasks done

v-t rendering is slower than $t() #1712

amurf opened this issue Jul 17, 2024 · 0 comments · May be fixed by #1713
Labels
Status: Review Needed Request for review comments

Comments

@amurf
Copy link

amurf commented Jul 17, 2024

First of all, I realise Vue 2 is EOL and this repo is not actively maintained, but I feel as though this issue needs a fix and we are happy to do so, but just wanted some guidance and to confirm this is something that can be fixed and released still @kazupon

Ever since the changes made to fix this issue #450 the v-t directive it massively slower than $t() and it becomes more noticeable as your translation file grows.

This is because v-t is cloning the current locale messages into each element that uses the directive, so as you get more messages in your translation file, this operation starts to take a lot of time to copy all the messages. There is also a memory overhead for this approach that is not ideal.

It becomes extremely noticeable if you're rendering multiple translations per item using v-t in a for loop.

Relevant code:

Expected behavior

v-t is expected to be more performant based on the documentation (https://kazupon.github.io/vue-i18n/guide/directive.html#pros-2).

But really the expected behaviour I would say is that it doesn't copy the entire active locale messages and renders in a similar time to $t() as it has the benefit of being cached.

Reproduction

https://stackblitz.com/edit/vitejs-vite-92c8pm

This is rendering with v-t and $t at the same time, then will show the render time in the UI for each. If you add more items to render as part of the loop, you'll see the gap widen more and more.

Even if you have a small translation file, v-t still seems to be slower.

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 4.58 GB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.17.1
    npm: 8.15.0
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5
  npmPackages:
    vue: 2.7.12 => 2.7.12
    vue-i18n: 8.28.2 => 8.28.2

Screenshot

No response

Additional context

In our app, we had a page using the v-t directive with around ~3000 items per locale in our translation files and using v-t to render around 400 items, the page was taking 4s to render, which performance profiling shown was all due to looseClone() in vue-i18n. You could suggest pagination, but swapping to $t() instead of v-t the page renders near instantly, so clearly this performance is fixable.

This was also raised as a discussion here -> #1650 which I replied to as well.

Validations

@amurf amurf added the Status: Review Needed Request for review comments label Jul 17, 2024
@liam-megaport liam-megaport linked a pull request Jul 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Review Needed Request for review comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant