Caching jQuery objects seems especially beneficial on UXP browsers

General project discussion.
Use this as a last resort if your topic does not fit in any of the other boards but it still on-topic.
Forum rules
This General Discussion board is meant for topics that are still relevant to Pale Moon, web browsers, browser tech, UXP applications, and related, but don't have a more fitting board available.

Please stick to the relevance of this forum here, which focuses on everything around the Pale Moon project and its user community. "Random" subjects don't belong here, and should be posted in the Off-Topic board.
User avatar
UCyborg
Board Warrior
Board Warrior
Posts: 1149
Joined: 2019-01-10, 09:37
Location: Slovenia

Caching jQuery objects seems especially beneficial on UXP browsers

Post by UCyborg » 2025-08-02, 05:36

I've been messing with the web app at work recently, which uses jQuery library a lot, on one page, there is a table with records on the left and records' settings on the right, settings are on a form with numerous checkboxes, some text fields and select dropdowns. Devs don't seem to cache jQuery objects, even chaining jQuery function calls to manipulate the same object doesn't seem like a common appearance at first glance. I changed the code on that page, stored objects referring to frequently used elements on the page in a variable (plain JavaScript object) on page load, previously, the function that updates the form eg. when you select the entry in the table, needed anywhere from 140 ms to 220 ms to execute on Pale Moon. Now it's done in 46 ms to 78 ms. The function was also needlessly removing and adding event listeners on form elements, these could be just added once when the page is loaded. I timed it with console.time() and console.timeEnd() functions.

The improved responsiveness is noticeable without measuring. For reference, Firefox got from about 30 ms to 15 ms while Chromium got from about 60 ms to 30 ms.
The Merovingian wrote:Choice is an illusion, created between those with power, and those without.

User avatar
Moonchild
Project founder
Project founder
Posts: 39720
Joined: 2011-08-28, 17:27
Location: Sweden

Re: Caching jQuery objects seems especially beneficial on UXP browsers

Post by Moonchild » 2025-08-02, 10:12

This is what happens when someone with just a little bit more understanding of the underlying language has a look at code and spots bottlenecks :D
Maybe let the devs know they are leaving a ton of performance on the table by constantly pulling from the lib.
"Sales hates anything that can't be turned into a confident sentence." - anonymous warehouse worker
"Why debate someone you fundamentally don't trust?" - Dario Amodei
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
UCyborg
Board Warrior
Board Warrior
Posts: 1149
Joined: 2019-01-10, 09:37
Location: Slovenia

Re: Caching jQuery objects seems especially beneficial on UXP browsers

Post by UCyborg » 2025-08-04, 16:40

That's what I intend.

Wrapping code doing a lot of DOM updates in requestAnimationFrame() is also helpful, now the elapsed time no longer shoots up to 70s and it can get as low as 30 ms on Pale Moon. Clicking the entry in a table, which populates the form, there's still a small delay on Pale Moon, but it got from delayed (before caching was added) to practically instant on Chromium/Firefox, at least that's how it feels. I don't know if it can be improved further.
The Merovingian wrote:Choice is an illusion, created between those with power, and those without.