All blocks

Blog post

An article at reading width with its sections listed beside it, marking the one you’re reading.

npx shadcn@latest add checkfu/uicontext/blog-post
All postsEngineering

How we made search return in under 100 milliseconds

A million issues, a hundred filters and one input box. What we tried, what we measured, and the index we ended up with.

Sofia LindqvistEngineering, Search · 9 min read

Last spring, search on our largest workspace took 1.8 seconds at the 95th percentile. People had stopped using it; they scrolled instead. This is how we got it under 100 milliseconds, and what we’d do differently.

What we measured

We logged every query for two weeks, with its filters and the time each stage took. Three things stood out:

  1. Most queries were two words or fewer.
  2. Nine in ten had at least one filter, usually status or assignee.
  3. Half the time went to sorting results we never showed.

The index

We moved from one big index to one per workspace, with the common filters stored beside each word. A query now reads only the rows that can match:

const hits = index.search(words, {
  filter: { status: ["todo", "doing"] },
  limit: 50,
})

Filters stored beside the words cost 12% more disk. We decided that was worth it; see the numbers.

Ranking without a second pass

Sorting moved into the index too: each list of matches is kept in order of last update, so the first 50 are the 50 we show. No second pass.

I typed half a word and it was there. I thought I’d hit a cached page.
— A customer, the week it shipped

What we’d do differently

Measure first. We spent a month on a faster tokenizer before we learned that tokenizing took 3% of the time.

Components usedAvatar