3 ms·
This makes me so very very glad I'm not a web javascript guy : INTERVIEWER: So, you may be able to guess, that there is a problem with this code. It is
by waps 13y ago
This makes me so very very glad I'm not a web javascript guy :
INTERVIEWER: So, you may be able to guess, that there is a
problem with this code. It is very inefficient. If you
type a string with 30 characters into the text box, the
server gets called 30 times. Not good, we are having all
kinds of issues with scalability so we can’t afford to be
writing code like this.
Calling code 30 times is a problem. Sure there's a few places that might be true. Is this a device driver ? A video decoder maybe, or something else that's horribly complex ? Nope, just the most basic MVP website. Oh my fucking god. I remember programming on windows in Delphi, and on linux in QT. In both cases doing autocomplete the naive way just fucking works. Even with millions of possible completes.
I remember implementing a function plotter that just completely refreshed a canvas pixel-by-pixel upon keydown. Not a problem. Even re-rendering a robot's simulated environment every keypress was nowhere near problematic.
And now we're worried about a 30 times called dead simple function, in the most basic of websites. Wow.
Progress.
(I understand why this happens. Server latency ... just works that way I guess. But I don't have to like it. HTML page layout is another peeve of mine. Resizable layouts are a solved problem in every single GUI toolkit except for one. Custom components are another seriously lacking web thing. It is a major javascript accomplishment to display a custom temperature-like gauge ... wtf ?)
- TheZenPsycho 13y agoUhhh isn't making 30 seperate network connections in a second a scalability problem regardless of language or platform? if the target server is apache, that's spinning up a thread for every keystroke, for one user, and you think this is a problem unique to javascript, why?
- drewblaisdell 13y ago> And now we're worried about a 30 times called dead simple function. Wow. This problem is not unique at all to the browser environment. You should probably throttle/debounce autocomplete events any time a server is involved.
- waps 13y agoTrue. In those toolkits, generally no server was involved.
- misterjangles 13y agoIt can be a huge problem depending on the query that the server is running and the amount of traffic on the site. Avoiding completely useless auto-complete queries is fairly low-hanging fruit since it's so easy to fix.
- anonfunction 13y agoCalling a function 30 times isn't the problem. It's calling the server 30 times that is the problem.