DEV Community

Cover image for The Radar Gun Problem
Conlin Durbin
Conlin Durbin

Posted on • Originally published at wuz.fyi on

4 1

The Radar Gun Problem

The other day, I was driving home from an event and there was a massive slowdown on the highway. I assumed that there was a crash or some construction up ahead, but as I got closer to the bottleneck, I realized that the only difference was that there was a cop standing on the side of the highway with a radar gun. Just the presence of a monitor slowed down the performance of the system.

Later that week, I was debugging some Javascript code and ran into a problem I have hit a few times. I had a fairly intensive process looping over a lot of values. I took the standard approach to debug a JS problem and dropped in a console.log. I refreshed the page, opened the console... and almost crashed my browser.

Calling a console.log with an intensive process takes a lot of memory, it turns out. I've run into this before, but this time the traffic slowdown really made me think about it. Let's talk a bit about something I'm calling the RadarGun Problem.

In many situations, the fix for the problem is changing where the observation happens. Moving the console.log outside of the loop - either after or before -is a good option. You can also change the method of observation - drop in adebugger; and step through it, introducing a purposeful bottleneck to prevent an accidental one.

Have you run into this before? How have you solved it?

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
tchaflich profile image
Thomas C. Haflich

Seems like a variant of the Heisenbug.

Usually when I come across one, I end up having to refactor something anyway - whatever was janky enough to make me want to test it is usually janky enough to break apart into more easily testable pieces when it slows down or does something weird.

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay