Hacker News new | ask | show | jobs
by crispyporkbites 2972 days ago
I think a JS SPA is a good fit for this. A common search use case is trying to find something obscure, which usually takes a few different searches. Once you've loaded up the SPA once (ie. your 4 second delay), you are able to do multiple searches quite rapidly as the subsequent post requests are tiny (3kb out 16kb in), new DNS resolution / TLS connections won't be required for at least a few minutes.

So if I'm doing more than one search, which I would guess is the way most people use it, then the current implementation will be much, much faster than doing a full page reload on every search.

2 comments

>Once you've loaded up the SPA once (ie. your 4 second delay), you are able to do multiple searches quite rapidly as the subsequent post requests are tiny

I don't think parent poster is talking about initial page load. Instead, the search page's javascript intercepts every keydown event so you would suffer 4 second round-trip delay for every keystroke. (You can go see this in browser's developer tools by setting a breakpoint on the keydown event.)

Instead of this:

  [4 seconds] page load done, type "Ruby"
It's this:

  R [4 seconds] u [4 seconds] b [4 seconds] y [4 seconds]
More examples of this keydown latency frustration are retail websites like homedepot.com and lowes.com. When you're at home on a fast fiber optic connection, the keydown events work fine. (Customers generally like the "autocomplete" feature that the keydown javascript code enables.) However, when I'm at the store with a mobile phone on a slow 3G connection, each keydown takes 5 seconds and it makes it impossible to use the website.
Nah, the four seconds is just when it has no open connection. Provided there is an open connection (that is, you performed a search on that instance of the page in the last minute or so), searching is just one round trip away—sure, latency to Canada is a few hundred milliseconds, but you’re not going to get any faster than that without edge searching.
I don't think that's right, at least for algolia (maybe others are implemented badly):

- The latency for this query will never be 4 seconds (it's a tiny request/response, TLS connection is open already etc.)

- There's throttling applied so if you're typing it won't send the request until you've finished typing

- You don't have to wait for the previous response to come back to type another letter

Finally, the real time searching means you'll probably find what you're after faster as you don't have to complete the full word for it to appear.

Your argument is entirely unsound.

The cost difference between producing JSON and producing full HTML should be negligible, half a millisecond at most, and only a few extra kilobytes to the response (still tiny). (I’m deliberately ignoring the question of whether Algolia can emit HTML, talking rather about a theoretical system, or a system that proxied Algolia to sort that part out.) And the extra CSS and JavaScript required should be trivial.

Therefore, the difference between a full page load and slurping JSON and crafting a new DOM should be a matter of a few milliseconds at most. (And you can add a tiny JS handler that does the new page load as XHR and just replaces the body without needing to reparse any JS and CSS to shave most of those few milliseconds off if you are so disposed.)

As I assess it, the benefits of the JS SPA are a few milliseconds on each search—a frame or two at the most.

But the costs are that the first search is very slow, twice as slow in the best-case scenario (due to using a different domain—if the same domain was used, the absolute best case would only be ~33% slower, more like 40% in practice) and much worse on slow devices or higher latency environments.

The first search is the most important one and the most common one. To be sure, some will perform multiple searches, but most sessions will involve only one search.

In summary: the SPA approach has marginal benefits but severe downsides. It is not necessary or desirable for a web app like this.