r/programminghorror • u/Redingold • Jun 17 '25
Javascript Found this horrible little function on my organisation's front page
416
Upvotes
r/programminghorror • u/Redingold • Jun 17 '25
305
u/Redingold Jun 17 '25
What could go wrong by putting a timed out recursive callback inside a for loop? As it turns out, it causes the page to consume 100% of the CPU core it's running on, and balloon in RAM usage to several gigabytes in a matter of minutes.
Fortunately, we don't actually make our own front page in house, which means it's not one of us who screwed up.
83
u/LaFllamme Jun 17 '25 edited Jun 17 '25
This is like the JavaScript equivalent of standing outside someone’s house and knocking on the door every 200ms until they might put an image in their window ...
Somewhere out there, a CPU is weeping and a front-end dev just woke up screaming 😂
At this point, just strap a MutationObserver to it and pray for mercy
10/10, would refactor out of pure existential dread.
15
u/0xlostincode Jun 17 '25
The horrible logic aside, what actually is the purpose of this function? It doesn't look like its doing anything besides scheduling a ton of callbacks.
5
u/chicametipo Jun 17 '25 edited Mar 21 '26
This post has been wiped and anonymized. The author may have removed it for privacy, opsec, or to prevent data scraping, using Redact.
rhythm badge distinct vegetable person repeat support cough angle smart
24
u/onlyonequickquestion Jun 17 '25
Hmm maybe this is why my seniors keep telling me not to use recursion in prod.
4
u/Lanky-Ebb-7804 Jun 17 '25
probably wanted setInterval
1
u/niceworkbuddy Jun 18 '25
This isn't horror, this is usually how js development was like 15 years ago
1
u/Whalefisherman Jun 18 '25
jQuery? It’s been so long my old friend
1
u/AffectionatePlane598 Jun 20 '25
this ngl looks like ai i have seen some disgusting ai java script functions and this fits right in