P99 0 ms* autocomplete for 240M domain names

(ruurtjan.com)

80 points | by dbalatero 4 hours ago

12 comments

  • skybrian 3 hours ago
    This autocomplete suggests domains that don't exist. You can just type garbage and it will suggest something, but then if you go there, there are no records.

    It seems like one purpose of an autocomplete box is help you avoid typos, so that makes it less useful.

    • bawolff 23 minutes ago
      The autocomplete seemed to suggest real domains to me. If you typed in garbage it suggested the garbage plus a bunch of common TLDs - that seems like a reasonable choice to me. In any case, if your issue is the list of domains to suggest, its trivial to change that to a different list.
    • pierrefermat1 1 hour ago
      Yes, OP seems to have completely lost touch with what is actually useful vs optimizing metrics for the sake of it.
      • lnenad 44 minutes ago
        But there is a cool blog post about it though.
  • chrismorgan 2 hours ago
    Using keyup makes no sense and is inconsistent with user expectations. For triggering actions (which includes normal typing), you only ever use keydown. (Well, there’s one exception for reasons unclear to me: activating a button by pressing Space. That triggers on keyup like how clicks are on release, while Enter triggers on keydown.) Keyup is limited to things where you’re constantly reacting to the state of a key, as is common in games.

    This affects the functionality, too. It is in fact introducing latency by using keyup instead of keydown. Feels bad.

    • hnlmorg 41 minutes ago
      Key down is used for events that can be duplicated by holding the key. Eg in a text editor, when you want multiples of the same letters, you’d press and hold the key.

      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.

    • danbruc 28 minutes ago
      For triggering actions (which includes normal typing), you only ever use keydown.

      I think you have this wrong, actions generally occur on button release, until that you can move the mouse cursor to a different target, tab to another control, use [ESC] to cancel, and so on. Typing, moving a slider with the cursor keys, and similar things that make use of key repetition while holding down the key are the exception to this.

    • zxexz 2 hours ago
      As a user, I’ve not thought too much about this before now. I agree with you mostly, but the keyup on space behaviour actually feels so innate I’d hate any change to it. Keydown on space is “jump”; nothing else.
      • chrismorgan 2 hours ago
        I’d just like to hear an explanation of why it is. Because if you handled “is key currently pressed” events with polling rather than events (which is how people almost always consume them logically), it would be the only thing in the entire world that I can think of that would/should use keyup.

        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.)

        • Rygian 1 hour ago
          Because in those contexts, the Space key is being used as a physical mirror of the on-screen button, and on-screen buttons are UX'd to perform action when released.

          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).

          • regularfry 1 hour ago
            Yes, the bailing-out explanation is right. With a mouse it's intentional that you should be able to push the pointer off the button with the mouse button still pressed to cancel.
          • chrismorgan 58 minutes ago
            (Esc while Space is held doesn’t cancel, but Tab does.)

            You’re only answering half of the inconsistency: because Enter activates buttons like any other key, on keydown.

        • podocarp 1 hour ago
          It just matches real life. What about lmb to shoot? You don't fire a gun on trigger release, you fire it on trigger down. Walking? Would be weird moving only on keyup.
          • wky 1 hour ago
            This raises the question of why real life buttons and virtual buttons behave differently. My unsubstantiated guess is that clicks act on release to give the opportunity to slide off the button to abort, and/or because the button would disappear while pressing if it ex. submits a form.
        • dangond 2 hours ago
          Jump is keydown because many games let you adjust your jump height based on how long you hold down space after the jump starts.
  • ViscountPenguin 3 hours ago
    Unfortunately this approach doesn't feel that great down here in Australia, definitely a function of latency.

    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.

  • oersted 2 hours ago
    Why not just trigger the fetch on keyDown and show it as soon as the response arrives, as usual?

    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.

  • kevmo314 3 hours ago
    If you’d like to reduce the network latency further you can store each trie node as a file, naming it conveniently the prefix path to that node. Then dump the few hundred million files onto R2.

    Now the traversal can be done completely via CDN lookups!

  • camel_gopher 3 hours ago
    Clever but that’s not how we measure latency.
    • dbalatero 3 hours ago
      When it comes to UX, perceived latency is king.
      • wky 3 hours ago
        The perceived latency starts from keydown, not keyup. Redefining latency to start at keyup reduces measured latency, not perceived latency, and delaying the visual display to keyup makes perceived latency strictly worse, not better. Even sticking with the keyup definition, just displaying the result as soon as it is available gives the possibility of negative (defined) latency.
        • weird-eye-issue 3 hours ago
          I think you don't fully understand. They aren't just doing a search based on the key being pressed down. They already did a search based on the previous characters that returned results for all possible next characters. So by the time you type a second character it just checks results locally from the search that had likely already been returned from when you had typed the previous character.
          • wky 3 hours ago
            They do that, yet proceed to kneecap the perceived latency by delaying the render.

            > And on keyUp (the user releases the key), we render the suggestions.

            • weird-eye-issue 2 hours ago
              There are a large number of edge cases where rendering it on key down would not be desirable (user types Ctrl+v, how accented characters are enetered, how some Asian languages get handled, backspace/delete, user holds a key down, etc). This is getting into the point of optimization where it simply does not matter and can actually harm things
              • wky 1 hour ago
                Holding a key would indeed require both on key down and up. I'd still argue that handling rerender on key down (or to fully match whatever OS/browser semantics, oninput) makes more sense than key up. Pressing Ctrl+V for example produces feedback as soon as "V" is pressed, not when Ctrl and/or V is released.

                Interestingly Ctrl+V on OP's website does update immediately when Ctrl+V is pressed.

      • vasco 1 hour ago
        What you said might be true and yet what OPs AI agent did wasn't measure latency of the service nor calculated a p99 for it.
  • bagels 3 hours ago
    Looks more like 500ms?
  • cortesoft 3 hours ago
    KeyDown events don’t work great for mobile, though.
  • pupppet 3 hours ago
    Autocomplete aside, this is a pretty nifty tool.
  • pixelpoet 3 hours ago
    Pretty sure we mean < 1ms rather than actually instantaneous.
    • weird-eye-issue 3 hours ago
      On a technical level yes but once you factor in monitor refresh rates then you can get to levels of optimization where it simply doesn't matter because you are constrained by waiting for the refresh rate anyways.
    • lovich 3 hours ago
      Its like tic tacs saying they are 0 calories because they got the per serving size down low enough to round to 0.
  • ChannelFence 3 hours ago
    its pretty clever but what happns when someone pastes a domain or uses IME or voice input? the api being that fast is still impressive.
  • AboozarEsmaili 3 hours ago
    [flagged]