question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Potential Mistake in translate.js leads to performance issue

See original GitHub issue

Hello team,

why is here an addBack??! image

In some occasions this leads to document beeing included into the search, thus find("*") matches every single element on the page:

image

Yes, this is followed by some filters, but still, why do one pass a container to look in, when afterwards whole page gets scanned anyway?

image

On my (quite strong) machine this leads to 360ms delay loading the devices.

Thanks and best regards

Thiemo

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
theimo1221commented, Aug 1, 2021

Atleast on my machine switching the speed increased quite a lot:

image

360ms at the start and now 12ms

1reaction
theimo1221commented, Aug 1, 2021

I guess I solved the puzzle:

image

Calls:

  1. their original one having 40625 matches.
  2. Without the .addBack() having 0 matches
  3. Checking which elements where selected before the filter
  4. Swapping the order of find("*") and .addBack() resulting in 286 matches, all being within the specified container (".j_rooms, .j_functions")

So in my opinion, they not just wanted to find those containers, but also all elements within those containers. Keeping that in mind .addBack() is definitly necessary but has to be after the lookup for all elements within. So swapping lines 20 and 21 within translate.js results in following logic:

  1. Find the desired containers
  2. Find all the elements within the desired container
  3. Merge both set of found elements

I’ll prepare a PR later on

Read more comments on GitHub >

github_iconTop Results From Across the Web

The 10 Most Common JavaScript Issues Developers Face
The common errors that developers make while coding in JavaScript include mistaken thinking about how the "this" keyword works, incorrect assumptions about ...
Read more >
Javascript translations are loaded in the wrong order due to ...
The javascript translations file that enables translation of javascript strings is not loading, which may result in mixed languages on a page, ...
Read more >
Huge Performance Issues - WordPress.org
The translated version is expected to work slower in the secondary language due to the nature of the plugin. We need to parse...
Read more >
Getting Google Translate plugin Corrections and Suggestions ...
Removing the associated google-translate-customization -meta tag makes it possible to send in suggestions, but these suggestions does not show ...
Read more >
Handling common JavaScript problems - MDN Web Docs
Let's get to work. The error is now being thrown at line 51. Click on line number 51 in the center panel to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found