Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Front-end performance - Making lunr.js fast
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Oliver Nightingale
May 02, 2013
Technology
1.4k
2
Share
Front-end performance - Making lunr.js fast
Three stories about making lunr.js searching fast
Oliver Nightingale
May 02, 2013
More Decks by Oliver Nightingale
See All by Oliver Nightingale
d3_meetup_20120130.pdf
olivernn
1
63
D3 Geo Visualisations
olivernn
3
2k
Other Decks in Technology
See All in Technology
スケーリングを封じられたEC2を救いたい
senseofunity129
0
130
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
4
1.3k
AWS DevOps Agent or Kiro の使いどころを考える_20260402
masakiokuda
0
120
開発チームとQAエンジニアの新しい協業モデル -年末調整開発チームで実践する【QAリード施策】-
kaomi_wombat
0
280
私がよく使うMCPサーバー3選と社内で安全に活用する方法
kintotechdev
0
150
遊びで始めたNew Relic MCP、気づいたらChatOpsなオブザーバビリティボットができてました/From New Relic MCP to a ChatOps Observability Bot
aeonpeople
1
130
15年メンテしてきたdotfilesから開発トレンドを振り返る 2011 - 2026
giginet
PRO
2
250
Bref でサービスを運用している話
sgash708
0
220
AI時代のオンプレ-クラウドキャリアチェンジ考
yuu0w0yuu
0
670
AI時代のIssue駆動開発のススメ
moongift
PRO
0
320
不確実性と戦いながら見積もりを作成するプロセス/mitsumori-process
hirodragon112
1
160
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
17k
Featured
See All Featured
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
260
My Coaching Mixtape
mlcsv
0
90
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
How to Ace a Technical Interview
jacobian
281
24k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
350
How STYLIGHT went responsive
nonsquared
100
6k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
250
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
870
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
420
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
120
Transcript
FRONT-END PERFORMANCE MAKING LUNR.JS FAST Thursday, 2 May 13
100% CPU BOUND Thursday, 2 May 13
PROFILE TOOL Thursday, 2 May 13
BENCHMARK ๏ CONSOLE.TIME(‘ZOMG SLOW’) ๏ JSPERF.COM ๏ BENCHMARK.JS BEFORE &
AFTER Thursday, 2 May 13
DO LESS GO QUICKER Thursday, 2 May 13
lunr.Vector = function (elements) { this.elements = elements for (var
i = 0; i < elements.length; i++) { if ( !(i in this.elements) ) this.elements[i] = 0 } } BEFORE Thursday, 2 May 13
lunr.Vector = function (elements) { this.elements = elements } AFTER
Thursday, 2 May 13
var zeros = [0] var zeroFillArray = function (length) {
while (zeros.length < length) { zeros = zeros.concat(zeros) } return zeros.slice(0, length) } ELSEWHERE Thursday, 2 May 13
RESULTS 10 100 1000 10000 100000 1000000 NON ZERO FILLED
ARRAY ZERO FILLED ARRAY 774,676 ops/s 3,234 ops/s http://jsperf.com/lunr-vector-init Thursday, 2 May 13
LESS RECURSION FUNCTION OVER-HEAD Thursday, 2 May 13
EVIDENCE Thursday, 2 May 13
lunr.TokenStore.prototype.getNode = function (token, root) { var root = root
|| this.root, key = token[0], rest = token.slice(1) if (!(key in root)) return {} if (rest.length === 0) { return root[key] } else { return this.getNode(rest, root[key]) } } BEFORE Thursday, 2 May 13
lunr.TokenStore.prototype.getNode = function (token) { if (!token) return {} var
node = this.root for (var i = 0; i < token.length; i++) { if (!(token[i] in node)) return {} node = node[token[i]] } return node } AFTER Thursday, 2 May 13
RESULTS 40000 80000 120000 160000 RECURSIVE ITERATIVE 152,008 ops/s 103,070
ops/s http://jsperf.com/lunr-tokenstore-getnode/2 Thursday, 2 May 13
BIG OHHH CHOOSING THE RIGHT ALGORITHM Thursday, 2 May 13
lunr.SortedSet = function () { this.length = 0 this.elements =
[] } SIMPLE DATA STRUCTURE Thursday, 2 May 13
OPERATIONS ๏ ADD(ELEM) ๏ INDEX_OF(ELEM) SORTED SET Thursday, 2 May
13
lunr.SortedSet.prototype.add = function (elem) { if (~this.elements.indexOf(elem)) return this.elements.push(elem) this.length++
this.elements.sort() } BEFORE Thursday, 2 May 13
SORT O(n log n) Thursday, 2 May 13
INDEX_OF O(n) Thursday, 2 May 13
lunr.SortedSet.prototype.add = function (elem) { if (~this.indexOf(elem)) return this.elements.splice(this.locationFor(elem), 0,
elem) this.length = this.elements.length } AFTER Thursday, 2 May 13
BINARY SEARCH O(log n) Thursday, 2 May 13
lunr.SortedSet.prototype.indexOf = function (elem, start, end) { var start =
start || 0, end = end || this.elements.length, sectionLength = end - start, pivot = start + Math.floor(sectionLength / 2), pivotElem = this.elements[pivot] if (sectionLength <= 1) { if (pivotElem === elem) { return pivot } else { return -1 } } if (pivotElem < elem) return this.indexOf(elem, pivot, end) if (pivotElem > elem) return this.indexOf(elem, start, pivot) if (pivotElem === elem) return pivot } ELSEWHERE Thursday, 2 May 13
lunr.SortedSet.prototype.locationFor = function (elem, start, end) { var start =
start || 0, end = end || this.elements.length, sectionLength = end - start, pivot = start + Math.floor(sectionLength / 2), pivotElem = this.elements[pivot] if (sectionLength <= 1) { if (pivotElem > elem) return pivot if (pivotElem < elem) return pivot + 1 } if (pivotElem < elem) return this.locationFor(elem, pivot, end) if (pivotElem > elem) return this.locationFor(elem, start, pivot) } MORE ELSEWHERE Thursday, 2 May 13
RESULTS 100 10000 1000000 LOW VALUE HIGH VALUE NON EXISTANT
INDEX_OF BINARY_SEARCH INDEX_OF BINARY_SEARCH INDEX_OF BINARY_SEARCH 4,818,044 ops/s 5,521,920 ops/s 4,768,333 ops/s 14,445 ops/s 23,150 ops/s 1,697,089 ops/s http://jsperf.com/lunr-sortedset-indexof Thursday, 2 May 13
END USER PERF THIS IS WHAT REALLY MATTERS Thursday, 2
May 13
RESULTS 75 150 225 300 0.2.0 0.4.0 38.477 ms 240.865
ms lunr.Index.prototype.search Thursday, 2 May 13