HI version is available. Content is displayed in original English for accuracy.
Advertisement
Advertisement
⚡ Community Insights
Discussion Sentiment
71% Positive
Analyzed from 820 words in the discussion.
Trending Topics
#keyup#latency#key#button#keydown#down#space#release#don#makes

Discussion (32 Comments)Read Original on HackerNews
It seems like one purpose of an autocomplete box is help you avoid typos, so that makes it less useful.
This affects the functionality, too. It is in fact introducing latency by using keyup instead of keydown. Feels bad.
Key up is used for when it’s important to only have one occurrence of that event.
Technically you could write code that made key down only react once. But the logical separation makes some sense.
Edit: I think people are misunderstanding me. I’m asking for an explanation of why, when you have a button focused, pressing Space activates on key up, rather than key down like literally everything else on the keyboard, including Enter on a focused button. (Mouse activates on release.)
These two interactions should behave identically:
- Hover over a button, press mouse button 1, release button 1.
- Tab over to a button, press spacebar, release spacebar.
Why on-screen buttons are UX'd to behave this way is a logical follow-up question. I'd wager that it gives a means to bail out of the clicking (e.g. by moving the mouse out of the on-screen button before releasing mousebutton 1, or by pressing Esc while having spacebar still depressed).
The time it takes to press a key is a reasonable target to aim at for API latency I suppose, but it is still an arbitrary target. Waiting to display until keyUp just adds more latency if your API is faster. Having it synced with keyUp doesn't make it feel more immediate to me.
I think you could get a lot closer by framing this as an optimization problem, where you use the full alphabet dictionary, but add a residual prediction which aims to cover as much of the remaining domain name tree as possible weighted by popularity. This tree could then be pre-baked and stored with the same system. This would probably get you p99 0ms even in Australia.
Now the traversal can be done completely via CDN lookups!