Throughput measurement for the hot paths, per #86.
npm run bench:ratios
That is one full pass followed by the A/B ratios, and it appends a record to
bench/history.jsonl — see
How to take a measurement for the other commands
and for what each of them prints.
Measured on dev after #159, #165 and #166 landed — four full-suite runs on an
idle machine, warm-up discarded, on Vitest 4. This table is the current
picture; the sections below are the historical record of how each finding was
found and diagnosed, and their numbers are deliberately not updated. The
suite now runs on Vitest 5 (#219). The ratio is defined exactly as before, and
a Vitest 5 pass reproduces the same picture within the run-to-run noise
described below, as far as a single pass can show: get_gaussian_kernel size 7
and check_subset were measured in one pass only, and those two can move
further — provided Vitest's getter instrumentation is off, which the
config does for you: see
The module-runner artefact under Vitest 5.
| case | 4 runs | status |
|---|---|---|
linalg.lu_solve |
1.43 / 1.49 / 1.46 / 1.47 | resolved — harness artefact (#169, see below); 1.00–1.02 on the built bundle |
homography2d.check_subset |
1.35 / 1.27 / 1.28 / 1.63 | resolved (#169): mostly the same artefact; the per-call new matmath() was hoisted too, 1.12 on the built bundle |
affine2d.run 3 pts |
1.34 / 1.31 / 1.30 / 1.41 | resolved (#169): same two causes; 1.12 on the built bundle |
math.get_gaussian_kernel size 7 |
1.23 / 1.21 / 1.16 / 1.15 | resolved (#169): harness artefact; flips sign run to run on the built bundle (0.92–1.09) |
homography2d.run 40 pts |
1.17 / 1.22 / 1.12 / 1.10 | resolved with the above: jsfeatNext faster on the built bundle |
yape06.detect |
1.02 / 1.04 / 1.06* / 1.03 | resolved (see caveat) |
yape.detect |
1.11 / 1.02 / 1.05* / 1.00 | resolved (#166) |
matmath.invert_3x3 |
1.03 / 1.09 / 1.12 / 1.10 | resolved (#165) |
linalg.svd_*, eigenVV |
all ≤ 1.17 | resolved (#159) |
imgproc.box_blur_gray radius 2 |
1.43 / 1.26 / 1.28 / 1.26 (jsfeat faster in all four, quiet machine; two loaded series agree) | new, open (#168, fix tracked in #251): 1.19–1.28 on the built bundle, so not the harness artefact. Suspected: the #114 rewrite (clamping ternaries and Math.floor(sum / area) in the inner loops). See the rest of imgproc |
gms.filter vs the matching step, default path — not an A/B ratio |
0.068 / 0.069 / 0.066 / 0.068 / 0.064 | new (#134): costs 0.07× the knnMatch + ratio_test step it follows. Rotation 0.47×, scale 0.32×, rotation+scale 2.3× — see GMS |
teblid.describe vs orb.describe, 300 keypoints — not an A/B ratio |
p256 1.55 / 1.62 / 1.55 / 1.54; p512 2.74 / 2.90 / 2.73 / 2.73 | new (#135): p256 costs 1.6× and p512 2.7× orb.describe on the same keypoints — see TEBLID |
freak.describe vs orb.describe, 300 keypoints — not an A/B ratio |
size 7 (all kept) 3.26 / 3.25 / 3.22 / 3.26; size 31 (132 kept) 1.66 / 1.66 / 1.63 / 1.65 | new (#80): costs 3.3× orb.describe per keypoint, about 2× TEBLID p256 — see FREAK |
| everything else | within ±1.12 | noise |
* = jsfeatNext faster in that run.
The gms.filter, teblid.describe and freak.describe rows are the exceptions to everything above it: jsfeat has no GMS, so it is a cost in units of the matching step in the same process (as "yape06 costs N× fast_corners"), measured on Vitest 5, not part of the four-run series above: gms.filter from five runs of bench/gms.bench.ts, teblid.describe from four runs of bench/teblid.bench.ts, freak.describe from four runs of bench/freak.bench.ts, each after one discarded warm-up.
One caveat on yape06. #166 measured it at 1.14–1.47 on its own branch and
concluded the alias had not helped there. On merged dev it measures ~1.04.
The improvement is real across four runs but not explained: the alias alone
did not produce it, so something in the combination of the three fixes did.
Recorded as unexplained rather than credited to any one change.
lu_solve was the last and tightest signal — 1.43–1.49 with a ±0.03 spread —
and #159 had predicted its fix could not touch it (lu_solve constructs no
internal matrix_t). Profiling it under #169 found the cause outside the
library: every number in the table was measured on source transformed by
vite-node, and that transform rewrites each import { x } from "./y" into
a per-call lookup on a module-namespace object. A cross-module helper such as
linalg_base's swap, called in lu_solve's pivot loop, therefore costs a
property load plus an un-inlined call per invocation — a cost the Rollup
bundle consumers install does not pay, because there every import is a
plain binding.
The probe that settled it (6×6 lu_solve, identical bytes, same process):
| variant | hz |
|---|---|
| jsfeatNext through the vite-node transform | 1.41 M |
same algorithm, imported swap captured into a local const |
2.26 M |
same algorithm, swap defined in the same file |
2.20 M |
jsfeatNext from dist/jsfeatNext.mjs |
2.12 M |
| jsfeat (reference) | 2.14 M |
Original jsfeat is immune because it is one IIFE per module: its swap is a
closure in the same scope. So the artefact only ever inflates jsfeatNext's
side of the ratio, and only for cases that cross a module boundary inside
the timed region — which is exactly the set of findings that survived #159,
#165 and #166. The two motion_model minimal-sample cases had a second,
real cause on top: a matmath and a linalg constructed per call, hoisted
to module-level instances in the same change (1.16–1.17 → 1.12 on the built
bundle, inside the noise floor).
How to read a ratio from now on: run npm run bench:dist (after
npm run build-ts) before treating any jsfeatNext-vs-jsfeat number as a
statement about shipped code. The default npm run bench stays as the
no-build, CI-smoke-checked harness; its ratios are upper bounds for anything
that crosses a module boundary. The numbers in history.jsonl were all
recorded on the default harness and remain comparable with each other, not
with bench:dist runs. Case names are the keys of that file, so they are
kept verbatim even where their parenthetical is now historical (the
check_subset case no longer allocates a matmath).
Vitest 5 replaced vite-node with Vite's module runner, and the artefact above came with it — plus one new, larger source of the same distortion that is worth knowing about because it is silent:
- While a benchmark runs, Vitest 5 wraps every export of every module it
transforms in a call counter (a
Mapread and write per access), so that it can print a "Benchmark Warning: accessed module export getters too many times". That bookkeeping sits inside the timed region and only on the jsfeatNext side — the vendored jsfeat is CommonJS, its exports are plain properties, nothing wraps them. benchmark.suppressExportGetterWarnings: true(set invitest.config.mts) switches the counter off entirely, not just the message. Do not remove it. One full pass each way on the same machine:cachesteady state 2.49x instead of 1.07x,linalg.lu_solve2.85x instead of 1.51x,math.get_gaussian_kernelsize 7 2.98x instead of 1.58x,matmath.invert_3x31.75x instead of 1.03x. Every case that crosses a module boundary inside the timed region moves like that; the millisecond-scale detector and imgproc cases do not.- With the counter off, what remains is the original #169 effect (plain getters
instead of vite-node's property loads), so the rule above stands unchanged:
the default
npm run benchratios are upper bounds for anything that crosses a module boundary, andnpm run bench:distis the one to read as a statement about shipped code. It still works under Vitest 5 and shows the same signature as before (linalg.lu_solveat 1.00x on the built bundle). - Re-check this on every Vitest bump. The flag does this job only because of
Vitest 5.0.x internals: it also gates the getter tracker, which nothing
promises. After a bump, one pass must print no "Benchmark Warning" and keep
cachesteady state near 1.0×.
Every case but one runs twice in the same process: once through jsfeatNext, once through the vendored original jsfeat (tests/vendor/oracle.cjs). What matters is the ratio between the two. The one exception is gms.bench.ts: jsfeat has no GMS, so it has no jsfeat side and times gms.filter against the matching step it follows (knnMatch + ratio_test), both inside jsfeatNext, and reports "GMS costs N× matching" (see GMS). Vitest 5's console prints one single-row table per side and no cross-side summary, so the ratio is computed by scripts/bench-ratios.mjs from the JSON reporter's output (npm run bench:ratios, or see How to take a measurement). It prints one line per case — the ratio is always ≥ 1, the next column says who won, and * marks anything above the ~1.15x noise floor (shape only — see the noise floor below before reading any single number as a result):
1.01x jsfeatNext imgproc.resample — float path
1.04x jsfeat imgproc.gaussian_blur — F32 path (_convol)
1.51x jsfeat * linalg.lu_solve (6x6)
The definition is unchanged from Vitest 4: jsfeatNext's hz divided by jsfeat's hz, where hz is operations per second from the mean latency. On Vitest 5 that is 1000 / period in the JSON — not the hz column of the console table, which Vitest 5 fills from throughput.mean, a mean of per-sample throughputs. The two are different averages of the same samples: the mean of the throughputs against the throughput of the mean latency. On a right-skewed latency distribution, which is what a bench produces, the first is the larger (a 40–50% gap was measured on a 33 µs case), so read ratios from the script, not from the table. bench/history.jsonl keys and values therefore keep their meaning.
The hz / mean columns in the console table are not comparable across machines, and largely not comparable across runs on the same machine either.
Absolute throughput depends on the CPU model, its thermal and boost state, what else the machine is doing, and the Node version. A shared CI runner has none of those pinned — it is a VM whose neighbours you cannot see — so its absolute numbers wander for reasons that have nothing to do with the code. (We have not measured that spread on this project's CI; the locally-measured jitter is in the noise-floor section below.) A number recorded on one box and diffed against another box reports noise as a regression — and the natural response (widen the threshold until it stops shouting) leaves you with a measurement that can no longer detect anything.
Running both implementations back to back cancels almost all of that. A slow runner halves both sides; the ratio survives. So:
- ✅ "jsfeatNext runs
gaussian_blurU8 at 0.94× jsfeat" — portable, comparable next month, comparable on CI. - ❌ "1240 ops/s" — true only for that box, that minute.
The ratio cancels the machine, but not the ordinary run-to-run jitter of a JIT language: GC timing, when V8 decides to optimise a function, cache state.
Measured on a developer laptop, gaussian_blur U8 across four consecutive runs
of an unchanged tree:
| run | result |
|---|---|
| 1 | jsfeat 1.06× faster |
| 2 | jsfeatNext 1.10× faster |
| 3 | jsfeatNext 1.14× faster |
| 4 | jsfeatNext 1.05× faster |
Note it changes sign. The two implementations are indistinguishable here — which is the expected result for a port doing the same arithmetic — and the spread is roughly ±10–15%.
So, in practice:
- under ~1.15× — noise. Do not investigate, do not "fix", do not record it as a finding.
- a consistent shift across several runs, or anything beyond ~1.2× — worth looking at.
Always re-run a few times before believing a number. A single run is a sample of one.
| Command | What it does |
|---|---|
npm run bench:ratios |
One full pass on the source, then the A/B ratios, appended to bench/history.jsonl (see below). Raw JSON lands in bench-results/ (git-ignored). |
npx vitest bench --run |
One full pass, console tables only: one single-row table per side, no ratios. |
npx vitest bench --run bench/linalg.bench.ts |
One file. Add -t "lu_solve" to narrow to one case (a name filter, matched against describe > test). |
npm run bench:dist |
The same pass against the built bundle (npm run build-ts first), the one to read as a statement about shipped code. Add the JSON reporter flags below to get ratios from it. |
npm run bench:smoke |
Collection only, nothing measured — what CI runs. See What CI does. |
npm run bench |
Watch mode. Rarely what you want. |
To see the ratios of a run without touching the history, run the pass with the JSON reporter alongside the default one, then reduce the file:
npx vitest bench --run --reporter=default --reporter=json --outputFile.json=bench-results/raw.json
node scripts/bench-ratios.mjs bench-results/raw.json # one line per case
node scripts/bench-ratios.mjs bench-results/raw.json --markdown--append bench/history.jsonl is what bench:ratios adds, and the only thing
that writes to the history. The ratio definition did not change with the
Vitest 5 migration (jsfeatNext hz ÷ jsfeat hz, see above), so existing
records stay comparable with new ones — subject, as always, to their env
block, and to the module-runner caveat above for anything recorded without
suppressExportGetterWarnings.
A full pass takes roughly four minutes: Vitest 5 gives every case a 1 s measurement and a 250 ms warm-up by default, and computing percentiles over the millions of samples a 100 ns case produces dominates the rest.
One describe per case, holding the setup and one test whose bench
fixture runs the two sides back to back:
describe("imgproc.resample — float path", () => { // setup: fixtures, pools, count assertions. Runs at COLLECTION time. const { next, orig } = f32Pair(); const dstN = new jsfeatNext.matrix_t(W >> 1, H >> 1, F32C1); const dstO = new jsfeat.matrix_t(W >> 1, H >> 1, OF32C1); test("jsfeatNext vs jsfeat (reference)", async ({ bench }) => { await bench("jsfeatNext", () => { jsfeatNext.imgproc.resample(next, dstN, W >> 1, H >> 1); }).run(); await bench("jsfeat (reference)", () => { jsfeat.imgproc.resample(orig, dstO, W >> 1, H >> 1); }).run(); }); });
What scripts/bench-ratios.mjs relies on:
- The describe's name is the case key in
history.jsonl. The test title is incidental. Rename a describe and its entries inhistory.jsonlstop lining up with the earlier ones. - The two tasks are named
"jsfeatNext"and"jsfeat (reference)", matched by prefix ("jsfeatNext (matrix_t)","jsfeat (reference, raw array)"and`jsfeatNext (${count} keypoints)`all pair up). A test that yields only one of the two is reported as an error row, never dropped. - An intra-library group says so in its describe. A test whose describe name contains
intra-library, and whose tasks are named after neither implementation (bench/gms.bench.ts: jsfeat has no GMS), is not an A/B pair and is not an error: the script prints each task's cost relative to the group's FIRST task, on its own, and never writes it tohistory.jsonl. Without the marker a group with neither name is an error row, and so is a marked group with a task that has no usable mean latency, each naming its actual cause. A name starting withjsfeat(any case) still has to pair up, so a mistyped side keeps failing loudly. - Two sequential
.run()calls, notbench.compare(). Sequential keeps the protocol the history was recorded with: jsfeatNext is warmed up and measured, then jsfeat is.bench.compare()warms every task up before measuring any of them, which is a different protocol from the one the history was recorded with.
Per-case lifecycle hooks go in the options argument, bench(name, options, fn);
they are the Vitest 4 setup / teardown options under their tinybench names,
and they fire once per phase (warmup, then run), never per iteration:
Vitest 4 bench(name, fn, { … }) |
Vitest 5 bench(name, { … }, fn) |
|---|---|
setup: (task, mode) => … |
beforeAll: (mode) => … |
teardown: (task, mode) => … |
afterAll: (mode) => … |
Keep the setup in the describe body, not in the test body. That is not style:
npm run bench:smoke skips every test body, so anything that lives in one is
invisible to it. See below.
What actually moves the numbers on a developer machine, roughly in order of impact:
| Factor | Effect |
|---|---|
| CPU contention | The dominant one. Another busy process means the OS scheduler hands the bench less CPU time — a browser with many tabs, a background build, an antivirus scan. |
| Thermal state / turbo boost | Has memory: the first seconds run boosted, then the clock drops under sustained load. So the first bench of a session tends to look faster than the last — a systematic bias in favour of whatever is measured first. |
| Power profile | On a laptop, on battery vs plugged in can change everything: Windows throttles aggressively on battery. |
| Memory pressure / GC | Smaller than people assume, but real: with RAM nearly full the collector runs more often and that time lands inside the measurement. Every case in this suite allocates its buffers outside the timed region — with one deliberate exception: cache.bench.ts's _pool_node_t.resize case, where the allocation being measured is the whole point, so it runs inside the timed region on purpose. |
In practice:
- Plug in the power — do not bench on battery.
- Close the browser and other heavy apps.
- Run twice, ignore the first run — it pays the JIT warm-up.
- If a number matters, run it 3–4 times. If the sign flips, it is noise.
The reassuring part: the A/B ratio already absorbs most of these effects, because both implementations meet the same conditions in the same seconds. That is precisely why the ratio is the metric. The steps above tighten the residual jitter — they are not what makes the measurement valid.
Judged against the noise floor above, not in isolation:
- A ratio drifting down across several runs and commits: jsfeatNext lost ground against the same reference workload. That is the regression signal.
- A ratio moving up the same way: an optimization landed, and by how much.
Since jsfeatNext is a port of jsfeat, ratios near 1.0× are the expected, healthy state — the two are doing the same arithmetic. A sustained move is interesting; a single-run move is not.
Resolved (with a caveat), and the original hypothesis was wrong.
This section long carried the theory that importing
hessian_min_eigen_valueacross modules blocked V8 inlining. Profilingyape06.detectrefuted it: 96.6% of the time is indetectitself and ~0.6% in the helpers, and the two implementations' inner loops are character-for-character identical.A structural probe then replicated
detect's body verbatim under four shapes, verified to find identical corner counts. Across three clean runs, two effects reproduced — a class method is slower than an object-literal property, and calling an ESM imported binding from a hot loop is slower than calling a plain module-scopeconstholding the same function (imported bindings are live, so each access carries an indirection). The second gained 12–28% every run, and is a one-line change.Aliasing the helpers to module-scope consts in
yape06.tsandyape.tsgave a split result:
case before (8 samples) after (4 samples) status yape8/8 jsfeat, 1.23–1.53 1.02* / 1.05* / 1.14 / 1.06* resolved — sign now flips yape068/8 jsfeat, 1.11–1.45 1.14 / 1.47 / 1.41 / 1.24 unchanged on this branch — but ~1.04 on merged dev, unexplained; see Current status* = jsfeatNext faster in that run.
The split is consistent with the profile rather than at odds with it:
yape06callscompute_laplacianonce per frame andhessian_min_eigen_valueonly for candidate pixels — which is exactly why the helpers showed 0.6%.yape's helpers sit in the per-pixel loop, so aliasing them matters there.yape06's alias is kept for consistency but measured no benefit; its cause remains unknown, and the class-vs-object effect the probe also showed is the remaining untested candidate.The measurements below are the pre-fix record.
The first real signal this harness produced. Eight samples, pooled from two separate sessions on an idle machine (power connected, browser and editor closed), each discarding a warm-up run:
| case | session A | session B | direction | verdict |
|---|---|---|---|---|
fast_corners thr 20 |
1.02 / 1.06* / 1.14 / 1.01* | 1.08 / 1.06 / 1.01* / 1.04 | flips | noise |
fast_corners thr 60 |
1.04 / 1.09 / 1.05* / 1.08 | 1.06 / 1.05 / 1.11 / 1.10 | 7/8 jsfeat | below floor |
yape06 |
1.30 / 1.33 / 1.38 / 1.27 | 1.45 / 1.35 / 1.11 / 1.32 | always jsfeat | real |
yape |
1.53 / 1.38 / 1.25 / 1.42 | 1.30 / 1.23 / 1.24 / 1.26 | always jsfeat | real |
* = jsfeatNext was the faster side in that run; every other figure favours jsfeat.
yape06 and yape favour jsfeat in all eight samples and sit around 1.3x.
That consistency of direction is the evidence — not any single magnitude. The
magnitudes are noisier than they first appeared: yape06 spans 1.11 to 1.45
and yape 1.23 to 1.53. Quote this as "roughly 1.3x", never to two decimals.
Note which case is tight is not stable between sessions: session A had
yape06 clustered and yape spread, session B the reverse. Four samples are
not enough to characterise a spread, only a direction. Do not read a tight
cluster within one session as precision.
fast_corners at threshold 20 changes sign and is plain noise. Threshold 60 is
more equivocal — jsfeatNext wins once out of eight samples (marked * above),
jsfeat the other seven, and none of the eight clears the ~1.15x floor.
Recorded as below-floor-but-directional rather than folded in with thr 20; it
is not a finding, and it is not quite nothing.
The first measurement was taken with a browser and editor open. It put
fast_corners as high as 1.23x and yape06 at 1.51x. On an idle machine
fast_corners collapsed into the noise floor while the YAPE gap held: CPU
contention had inflated everything, and only one of the two findings survived.
The second was worse, because the harness itself was wrong. set_threshold
mutates a singleton and was being called from the describe bodies, which
Vitest runs during collection — so both fast_corners suites actually ran at
threshold 60, and the case labelled "threshold 20" measured the same workload as
its neighbour. The ratio stayed valid (both sides ran at 60), but one case was
not measuring what it claimed to. Caught in review; see the threshold() helper
in detectors.bench.ts for the fix and why the obvious alternatives do not work.
That episode also cost an over-confident claim: an earlier version of this section reported the YAPE ratios as reproducing "to within +/-0.02". That was two samples. Eight give a range roughly ten times wider. The finding survived; the precision claim did not.
It is not an algorithmic difference: corner counts are identical on both sides (26,016 / 12,919 / 49,258 / 149), so both do the same work.
Leading hypothesis - not proven. jsfeat defines its per-pixel helpers as
closures inside the module IIFE, in the same scope as detect:
var hessian_min_eigen_value = function (src, off, tr, Dxx, Dyy, Dxy, Dyx) { ... };
jsfeatNext imports the same helpers from a separate module (yape06_utils.ts).
hessian_min_eigen_value runs once per candidate pixel — tens of thousands of
times per frame — and a local closure is a far easier inlining target for V8
than a cross-module import.
Confirming this needs a profile, not a benchmark. The cheap experiment is to
move the helper into the same module and see whether the gap closes; that is a
change to src/, so it belongs in its own issue rather than here (#86 is
measurement infrastructure and explicitly rules out micro-optimising).
There is deliberately no bench/results/*.json in the repo. A committed baseline invites exactly the cross-machine comparison described above, and produces noisy diffs on every run. The ratio is recomputed from scratch each time, which is what makes it trustworthy.
If historical tracking is wanted later, the thing to store is the ratio, not the raw hz.
| Case | Why it is here |
|---|---|
gaussian_blur — U8 fast path |
The most-used filter in the pipeline |
gaussian_blur — F32 path (_convol) |
Different cost profile; the float branch no test exercised until #87 |
resample — U8 fixed-point fast path |
Pyramid construction; the < 0x100 area-ratio branch |
resample — float path |
The non-U8 branch, bypassing fixed point |
orb.describe |
The per-frame hot spot (~5 ms in the pinball sample). Structurally unlike the filters: per-keypoint cost, sparse access through a rotated patch warp |
| Case | Why it is here |
|---|---|
fast_corners.detect — threshold 20 (~26k corners) |
The detector the ORB pipeline uses |
fast_corners.detect — threshold 60 (~13k corners) |
Half the corners: separates per-pixel scan cost from per-corner cost |
yape06.detect (~49k corners) |
The densest detector at these settings |
yape.detect — radius 5 (~149 corners) |
Needs init(); a very different corner density from the others |
Detector cost scales with the number of corners found, so the counts were verified identical on both sides before writing the benches — otherwise the ratio would compare workloads rather than implementations.
A second comparison comes free here: all four run over the same image in the
same process, so their hz are comparable to each other within a run.
"yape06 costs N× fast_corners" is as portable as the jsfeat ratio.
Phase 2 covers each module this way, one PR at a time. As of this PR every
module has a bench file: imgproc, orb, fast_corners, yape06, yape,
optical_flow_lk, linalg, motion_estimator, the cache pool, and
math/matmath/transform and motion_model. Within imgproc only
gaussian_blur and resample are benched — the other ~12 public methods
(grayscale, pyrdown, the derivative filters, the warps, canny, …) are
not yet covered. (#168 has since covered them: see
the rest of imgproc.)
| Case | Why it is here |
|---|---|
optical_flow_lk.track (~570 points) |
The other per-frame hot spot alongside orb.describe; a pyramidal search rather than a per-pixel scan |
Points are FAST corners on the same deterministic noise image, at a threshold
chosen to land in the few-hundred range — enough to amortise call overhead
without timing point-selection instead of tracking. Parameters
(win_size=20, max_iterations=30, epsilon=0.01, min_eigen_threshold=0.001,
3 pyramid levels) mirror examples/sample_oflow_lk.html's defaults rather than
being picked for the bench. curr_pyr is built from the same image as
prev_pyr — the tracker cannot tell a static scene from a stationary one, and
the point here is throughput, not accuracy (that is
tests/properties/optical_flow_lk.test.ts's job).
Measured over four runs on an idle machine: 1.03x / 1.23x / 1.10x jsfeatNext,
then 1.05x jsfeat — the sign flips and stays close to the noise floor.
No finding. Unlike YAPE, optical_flow_lk is close to a line-for-line port
(both sides share the same pyramidal-search structure), so parity here is the
expected result, not a surprise worth investigating.
Resolved. The fix for #159 (
matrix_tno longer re-allocates adata_typetable per construction) removed this finding. Post-fix, four idle-machine runs:
case before after status svd_invert1.29–1.40 (4/4 jsfeat, tight) 1.07 / 1.19 / 1.17 / 1.12 below floor eigenVV1.23–1.45 (4/4 jsfeat) 1.15* / 1.22 / 1.04 / 1.02 flips — noise svd_decompose1.31–2.75 1.12 / 1.04 / 1.01 / 1.15 below floor svd_solve1.29–1.44 1.06 / 1.09 / 1.13 / 1.07 below floor lu_solve1.34–1.88 1.34 / 1.55 / 1.24 / 1.43 still a finding — later 1.43–1.49, now the suite's tightest cholesky_solvenoisy 1.07* / 1.36 / 1.22 / 1.04* still noisy * = jsfeatNext faster in that run.
The four cases that construct internal
matrix_tinstances all dropped to or below the noise floor.lu_solvedid not improve — and #159's own "What this does NOT explain" section predicted exactly that, since it constructs no internalmatrix_t. It remains open and unexplained.The analysis below is kept as the record of how the finding was found and diagnosed.
| Case | Why it is here |
|---|---|
linalg.lu_solve / cholesky_solve (6x6) |
The affine motion model's normal-equation solve (AtA/AtB in motion_model.ts) |
linalg.svd_decompose / svd_solve / svd_invert / eigenVV (9x9) |
The homography DLT's eigen/SVD step (mLtL in motion_model.ts); the SVD variants are benched at the same size for comparability even though motion_model takes the eigen route |
Inputs are deterministic well-conditioned SPD matrices (MᵀM + nI), built
locally so both sides get identical bytes — see the module docstring for why
a poorly conditioned system would make the bench measure numerical luck
instead of throughput. lu_solve and cholesky_solve overwrite their operands
in place, so those two cases re-copy fresh input via the case's beforeAll
option once per phase (formerly bench()'s setup); the SVD/eigen functions are documented and verified not to mutate
their input, so they need no such copy.
Four runs on an idle machine, discarding a warm-up:
| case | r1 | r2 | r3 | r4 | verdict |
|---|---|---|---|---|---|
lu_solve |
1.44 | 1.88 | 1.54 | 1.34 | real |
cholesky_solve |
1.19 | 1.04 | 1.02* | 1.73 | noisy, mostly jsfeat |
svd_decompose |
2.75 | 1.31 | 1.42 | 1.32 | real (one outlier) |
svd_solve |
1.37 | 1.44 | 1.38 | 1.29 | real |
svd_invert |
1.31 | 1.33 | 1.32 | 1.34 | real, very tight |
eigenVV |
1.45 | 1.41 | 1.25 | 1.23 | real |
* = jsfeatNext was faster in that run.
jsfeat is faster in every sample of five of the six cases — svd_invert
reproduces to within ±0.02 across all four runs, tighter than anything else
measured in this suite so far. Only cholesky_solve is genuinely noisy
(direction flips once); the svd_decompose 2.75x in run 1 is a single outlier
against three runs clustered at 1.3-1.4x and is reported rather than discarded,
since discarding inconvenient samples without a stated reason (unlike the
CPU-contention episodes documented above) would be cherry-picking.
This is the same shape of result as the YAPE finding above, on a much larger
share of one module. Both are TS classes whose methods route through this
(here, this.cache.get_buffer(...) inside svd_solve/eigenVV), called
against jsfeat originals written as closures inside a single IIFE. Two
instances of the same pattern is not yet a proven cause, but it is now the
leading candidate for why jsfeatNext's class-based module design might carry
a throughput cost jsfeat's closure-per-module style does not, on hot paths
called thousands of times per frame. Recorded here as an open finding for a
future issue, same as YAPE — confirming it needs a profile, and any fix would
touch src/, which #86 explicitly rules out doing here.
Update: profiled (not just theorized) — see
#159. The this.cache
dispatch hypothesis above turned out to be wrong (0.1% of self-time in
svd_invert); the real cost is matrix_t re-allocating a data_type lookup
table on every construction. lu_solve/cholesky_solve's slowdown is not
explained by that fix, since neither constructs any internal matrix_t.
| Case | Why it is here |
|---|---|
motion_estimator.ransac (homography2d, 40 points, 6 outliers) |
The real per-frame call — examples/sample_orb.html fits a homography from ORB matches this way every frame |
motion_estimator.lmeds (homography2d, 40 points, 6 outliers) |
Same kernel, different iteration-acceptance rule (median residual instead of a threshold) |
Scoped to ransac/lmeds only — get_subset/find_inliers are internal
helpers the two call every iteration, and benching them standalone would time
a workload nobody calls directly. homography2d rather than affine2d: it's
the same 8-DOF kernel the linalg finding above traces back to, keeping the
two findings comparable. Input is tests/parity/motion_estimator.test.ts's
own fixture (40 correspondences, 6 gross outliers, fixed ground-truth
homography), already proven to converge identically on both sides — not a
shape invented for this bench.
RANSAC/LMEDS draw a random subset every iteration via Math.random, so both
sides need to draw the same subsets or the ratio compares different amounts
of work. The case's beforeAll option (formerly bench()'s setup) reseeds a
deterministic generator once per phase (not per call, unlike the parity test) — enough by induction, since
identical inputs and identical RNG state make a faithful port consume an
identical number of random draws, keeping both streams in lockstep for the
whole run. See the file's docstring for the full argument.
Four runs on an idle machine, discarding a warm-up:
| case | r1 | r2 | r3 | r4 | verdict |
|---|---|---|---|---|---|
ransac |
1.42 | 1.44 | 1.41 | 1.43 | real, very tight |
lmeds |
3.09 | 1.32 | 1.02 | 1.30 | real, noisy, one large outlier |
ransac is as tight as svd_invert from the linalg finding — jsfeat
consistently ~1.4x faster, four runs spanning barely 0.03x. lmeds favours
jsfeat in every sample too, but with real spread even ignoring the 3.09x
outlier (1.02–1.32, wider than anything else measured so far in this suite).
Reported rather than investigated further here — like the svd_decompose
outlier in the linalg section above, discarding it without a stated cause
(unlike the CPU-contention runs discarded elsewhere in this file, which had
one) would be cherry-picking.
Hypothesis confirmed. This section originally predicted that #159's fix
was "a plausible candidate to shrink this finding too", to be checked by
re-running after it landed. It was: post-fix, ransac measured 1.31 and 1.03
(against a pre-fix 1.41–1.44 that never flipped) and lmeds 1.14 / 1.15
(against 1.23–1.53). Both are now at or below the noise floor. The chain was
ransac → homography2d.run → linalg.eigenVV → matrix_t construction.
| Case | Why it is here |
|---|---|
cache.get_buffer + put_buffer — steady state |
The overwhelmingly common path: real callers request the same size call after call for the life of a session, so a node almost never needs to grow |
_pool_node_t.resize — forced every call |
The rare path (a fresh ArrayBuffer + four typed-array views), isolated by calling resize() directly with a fixed target size on one node borrowed once outside the timed region |
Unlike every other file in this suite, this one uses the real global
singletons rather than fresh instances — jsfeat.cache is a single
IIFE-closure object, not a constructor, so there is no new jsfeat.cache()
to fall back on. Both sides pre-allocate identically at module load
(allocate(30, 640 * 4)), so this isn't a compromise: it's the more
faithful bench, given jsfeatNext's shared-cache design (#41) exists
specifically to mirror jsfeat's one-pool-per-process model. The steady-state
case pairs every get_buffer with a put_buffer before the next iteration,
so the pool's size never drifts; the only side effect anywhere in this file
is that the one node the resize case borrows stays permanently larger, which
is harmless by the pool's own "at least this size" contract. See the file's
docstring for the full reasoning, including why an earlier version of the
resize case (growing the requested size every call) made the workload
depend on how many iterations each side completed, and why it was
redesigned around resize()'s own no-guard behaviour instead (caught in
review).
Four runs on an idle machine, discarding a warm-up:
| case | r1 | r2 | r3 | r4 | verdict |
|---|---|---|---|---|---|
| steady state | 1.07 | 1.17 | 1.14 | 1.14* | borderline, one flip |
resize |
1.08* | 1.05 | 1.04 | 1.06 | noise, close to 1.0x |
* = jsfeatNext was faster in that run; every other figure favours jsfeat.
Steady state sits right at the noise floor, not clearly a finding: three
of four samples cluster at 1.07–1.17x (jsfeat), the fourth flips to
jsfeatNext at the same 1.14x magnitude. At 11+ million operations/second each
call is under 100 nanoseconds, close to what performance.now()'s
resolution can distinguish — read this as inconclusive rather than as either
parity or a slowdown, not confidently either way.
resize is clean noise after the redesign — 1.04–1.08x, flipping once,
none of it above the ~1.15x floor. Unlike the abandoned growing-size design
(which mixed workload asymmetry into whatever it was measuring), a plain
ArrayBuffer + typed-array-view allocation is generic V8 machinery on both
sides, not algorithm-specific code — a real difference here would have been
the surprise, not its absence.
| Case | Why it is here |
|---|---|
math.get_gaussian_kernel — size 7 / size 9 |
imgproc.gaussian_blur's kernel build. Split because size <= 7 && odd && sigma <= 0 takes a hardcoded coefficient table and anything else falls through to a Math.exp loop — two different cost profiles, like imgproc's U8/F32 split |
math.qsort (2048 floats) |
Public API with no in-tree caller, but the one genuinely algorithmic routine in math (hybrid quicksort/insertion sort) — the kind of code a port drifts on |
math.median (512 floats) |
motion_estimator.lmeds's residual median |
matmath.transpose — 9x9 |
linalg.svd_decompose has five transpose call sites, in mutually exclusive/optional branches — at most 3 run per decomposition, and only 1 with SVD_U_T|SVD_V_T set. Benched at the size motion_model's homography DLT uses |
matmath.invert_3x3 / multiply_3x3 |
motion_model, per frame |
transform.invert_affine_transform / invert_perspective_transform |
Public API, no in-tree caller — see the calling-convention note below |
qsort and median rewrite the array they are given, so both restore fresh
input via beforeAll (once per phase). That is not a complete fix — within a phase,
iterations 2..N still work on already-processed data — but it applies equally
to both sides, so the ratio stays fair even though the absolute hz reflects
the sorted-input case.
math.perspective_4point_transform is deliberately not benched: it is
deprecated and logs a console warning on every call.
Two series were needed here, because review found two cases were measuring
the wrong thing (details below). The numbers here are from the second series,
after those harness fixes — four runs on an idle machine, discarding a
warm-up. They predate the invert_3x3 fix; that row's current status is
in the box below the table.
| case | r1 | r2 | r3 | r4 | verdict |
|---|---|---|---|---|---|
get_gaussian_kernel size 7 |
1.15 | 1.08 | 1.03 | 1.34 | 4/4 jsfeat — later series puts it at 1.15–1.23, see Current status |
get_gaussian_kernel size 9 |
1.08 | 1.12 | 1.12 | 1.03* | below floor |
qsort |
1.05 | 1.02* | 1.08 | 1.18* | flips — noise |
median |
1.09* | 1.05* | 1.00* | 1.11* | 4/4 jsfeatNext, below floor |
transpose 9x9 |
1.04* | 1.09 | 1.19* | 1.20 | flips — noise |
invert_3x3 |
1.24 | 1.18 | 1.36 | 1.34 | was real — now fixed, see below |
multiply_3x3 |
1.11 | 1.03* | 1.12 | 1.06 | below floor |
invert_affine_transform |
1.09* | 1.23* | 1.02* | 1.01 | 3/4 jsfeatNext |
invert_perspective_transform |
1.12 | 1.05 | 1.00* | 1.05 | below floor |
* = jsfeatNext was faster in that run; every other figure favours jsfeat.
Resolved. Profiling attributed this finding entirely to the singular-matrix check that #120 added to
invert_3x3— a line original jsfeat does not have at all. Isolating the two halves of it:
variant ops/s jsfeatNext as written ( Math.abs(det) < JSFEAT_CONSTANTS.EPSILON)9.35M drop Math.absonly10.01M (+7%) hoist EPSILONto module scope only13.36M (+43%) both 14.57M jsfeat (no check at all) 12.47M The object property load dominates, not
Math.abs— for a function whose arithmetic is only ~30 float operations, one property read per call is not negligible. With both fixed, the standalone form is faster than jsfeat while keeping #120's semantics exactly (verified identical forNaNand-0).After the fix, eight idle-machine runs: 1.03 / 2.20 / 1.01 / 1.09 / 1.15* / 1.14 / 1.09 / 1.04 — seven of eight at or below the noise floor, and the sign now flips, where before it was 10/10 jsfeat and never below 1.18. The 2.20 is a single outlier, reported rather than discarded.
The remaining ~1.05x is method-dispatch overhead the standalone probe did not have: the probe measured a plain function, the real path goes through
jsfeatNext.matmath.invert_3x3.
matmath.invert_3x3 was the one real signal here, and it has since been
fixed. Across the two series above it favoured jsfeat in ten out of ten
samples (1.18–1.40) without once flipping. It is called per model fit in
motion_model (motion_model.ts:262), so it sits on the per-frame path. The
cause and the fix are in the box above; post-fix it no longer clears the noise
floor and the sign flips.
Everything else is at or below the ~1.15x floor in this series. median
favours jsfeatNext 4/4 but sits low enough to be directional-at-best.
get_gaussian_kernel size 7 also favours jsfeat 4/4 here; a later four-run
series on merged dev put it at 1.15–1.23, i.e. at or just above the floor
rather than below it — it is carried as open in Current status.
The qsort case was not sorting. math.qsort takes a less-than
predicate and uses it in boolean contexts (if (cmp(a, b)), ternaries). The
bench originally passed a conventional three-way -1/0/1 comparator — which
returns a truthy value for both orderings, so the algorithm saw "a < b" as
true in either direction. Verified with a probe: sorting [5,3,9,1,7,2,8,4,6,0]
returned 8,4,6,0,5,3,9,1,7,2, completely unordered. The case was timing a
non-sort. Fixed to the same predicate shape tests/parity/math.test.ts uses;
the verdict happens to be unchanged (noise either way), but it now measures
sorting.
The transform comparison confounded two variables. It passed jsfeat a
packed JS array (Array.from) while jsfeatNext used a Float32Array — V8
stores and optimises those very differently, so the ratio mixed the
calling-convention question with an element-storage difference. Both sides now
use Float32Array, leaving matrix_t-vs-raw as the only difference. This
strengthened rather than overturned the conclusion: with the confound removed,
invert_affine_transform favours jsfeatNext in 3 of 4 runs.
An earlier series ran while the machine was busy, and it supported three
conclusions the idle re-run dismantled: get_gaussian_kernel size 7 looked
like a clean 6/6 directional result and then flipped twice, transpose
likewise, and qsort looked like the one case jsfeatNext consistently won
(5/6) before becoming an even split. Only invert_3x3 survived — and it got
tighter, the same signature the YAPE finding showed. Contention does not
just add scatter; it manufactures apparent direction.
A prediction also failed, and is worth recording as such. The module docstring
originally argued transform should measurably favour jsfeat, since
jsfeatNext's methods take matrix_t and unwrap .data while jsfeat's take
raw arrays — two extra property loads on a function that is a dozen float
operations. Across both series neither transform case clears the noise floor
in jsfeat's favour. The matrix_t calling convention has no throughput cost
this harness can detect; the docstring now states that null result instead of
the prediction.
Largely resolved. #159's fix cascaded here, as predicted:
new matmath()is cheap in itself, butmatmath's methods constructmatrix_t, which is where #159 bit. Post-fix, four idle-machine runs:
case before after status affine2d.run3 pts3.15–3.87 1.40 / 1.09 / 1.41 / 1.18 collapsed affine2d.run40 pts1.44–1.69 1.22 / 1.04 / 1.11* / 1.12 below floor homography2d.run4 pts1.22–1.73 1.25 / 1.01* / 1.11 / 1.19 below floor homography2d.run40 pts1.15–1.38 1.08 / 1.05 / 1.08 / 1.09 below floor homography2d.check_subset1.11–2.11 1.24 / 1.34 / 1.01* / 1.30 improved, still directional error(both)noise noise unchanged, as expected * = jsfeatNext faster in that run.
affine2d.runat 3 points — the largest ratio this suite ever measured — went from ~3.5x to ~1.27x. Theerrorcases, which never allocated, are unchanged: the control behaved as a control should.
check_subsetstill leans jsfeat's way. The threenew matmath()sites inmotion_model.ts(lines 212, 352, 541) are still there — #159 made each one much cheaper, it did not remove them.The analysis below is kept as the record of how the finding was diagnosed.
bench/motion_estimator.bench.ts measures ransac/lmeds end to end, so the
kernel's own cost is mixed with the estimator's loop. This file calls the
kernel methods directly, which is what makes the following attributable.
| Case | Why it is here |
|---|---|
homography2d.run / affine2d.run — 4 / 3 points |
The per-iteration hypothesis fit: RANSAC calls run on a minimal sample every iteration |
homography2d.run / affine2d.run — 40 points |
The final refit on the full inlier set |
homography2d.error / affine2d.error — 40 points |
The per-iteration scoring pass over all correspondences |
homography2d.check_subset — 4 points |
Called once per RANSAC iteration. affine2d.check_subset is a bare return true on both sides, so there is nothing to compare |
Correspondences are clean (no outliers), unlike motion_estimator.bench.ts's
fixture: these kernels are called directly, with no outlier rejection in play,
so gross outliers would only make run fit a meaningless model without
changing what it costs.
Eight samples, pooled from two idle-machine sessions, each discarding a warm-up:
| case | session A | session B | allocates? | verdict |
|---|---|---|---|---|
affine2d.run 3 pts |
3.28 / 3.47 / 3.70 / 3.15 | 3.34 / 3.45 / 3.47 / 3.87 | yes | real — largest in suite |
affine2d.run 40 pts |
1.69 / 1.54 / 1.46 / 1.51 | 1.44 / 1.63 / 1.60 / 1.53 | yes | real |
homography2d.run 4 pts |
1.22 / 1.31 / 1.33 / 1.51 | 1.26 / 1.73 / 1.32 / 1.34 | yes | real |
homography2d.run 40 pts |
1.15 / 1.31 / 1.33 / 1.24 | 1.30 / 1.26 / 1.18 / 1.38 | yes | real |
homography2d.check_subset |
1.35 / 1.45 / 1.32 / 1.36 | 1.15 / 2.11 / 1.36 / 1.11 | yes | real, but wide |
homography2d.error 40 pts |
1.03 / 1.11 / 1.06 / 1.05 | 1.02 / 1.16* / 2.91* / 1.18 | no | noise |
affine2d.error 40 pts |
1.09 / 1.10 / 1.05 / 1.05 | 1.07 / 1.06 / 1.01* / 1.09* | no | noise |
* = jsfeatNext was faster in that run.
Direction is the evidence, and it is unanimous: the five allocating cases
favour jsfeat in all eight samples without a single flip. Magnitudes vary
much more — quote affine2d.run at 3 points as "roughly 3.5x", not to two
decimals, and see the caveat below on check_subset.
The cause is visible in the code, and the shape of the result fits it.
jsfeatNext constructs a matmath instance inside three per-call methods —
affine2d.run (motion_model.ts:212), homography2d.run (line 352) and
homography2d.check_subset (line 541). Original jsfeat does not: its
equivalents call module-scope functions.
affine2d.runat 3 points — where the real arithmetic is nearly nothing — runs ~3.5x slower. A fixed per-call cost dominates entirely.- The same method at 40 points drops to ~1.5x: identical overhead, amortised over ~13x more real work.
error, the only pair of methods that allocates nothing, is the only pair that flips sign and sits in the noise floor — an unplanned but decisive control.
"Huge ratio on tiny inputs, shrinking as the input grows, absent where there is no allocation" is the signature of a fixed per-call allocation, and it is what these numbers show.
An earlier four-sample series put check_subset at 1.32–1.45 and this file
called it "tight". Four more samples widened it to 1.11–2.11. The
direction survived; the precision claim did not.
That is the same error this file already documents for the YAPE finding — "four samples are not enough to characterise a spread, only a direction" — made again, one section later, on a different case. Treat every tightness claim in this document as provisional until it has eight or more samples behind it.
This is the same class of defect as
#159 (matrix_t
re-allocating a data_type table on every construction) — and note the two
compound: each new matmath() here is itself cheap, but matmath's methods
build matrix_t instances, which is where #159 bites. Measurement only here,
per #86; the fix belongs in its own PR against src/.
bench/imgproc.bench.ts now covers every public imgproc method but one, and
pyramid_t.build. All on 640×480, with the same seeded noise on both sides
(RGBA noise for grayscale and skindetector).
| Case | Why it is here |
|---|---|
grayscale — RGBA to U8 |
The first step of every frame |
pyrdown, pyramid_t.build (4 levels) |
Every frame, for both the LK tracker and ORB |
compute_integral_image — sum only; sum + sqsum + tilted |
TEBLID (#135) and FREAK (#80) call the sum-only form: this is its baseline from before they did |
sobel_derivatives, scharr_derivatives |
Gradient maps; Scharr is what optical_flow_lk computes per level |
warp_perspective, warp_affine |
The AR overlay step; warp_affine carries the #119 fix |
canny |
Demo path; the one imgproc method that builds a matrix_t per call |
equalize_histogram, box_blur_gray |
Example paths; box_blur_gray carries the #114 fix |
skindetector |
Peripheral, but a plain per-pixel loop, so cheap to include |
Not benched: hough_transform. The vendored jsfeat version throws a
ReferenceError (it uses min_theta/max_theta without declaring them, under
"use strict"; see tests/parity/imgproc.test.ts), so there is no reference
side to pair it with, and an intra-library cost would answer no question anyone
is asking.
Identical work, checked. Every case runs both sides once at collection time
and throws unless their outputs agree (assertSameWork), so a ratio can never
compare two workloads. All are bit-exact except two, by design:
warp_affine: jsfeatNext fills the one-pixel band where a source coordinate falls in (-1, 0), which jsfeat extrapolates (#119). The check requires every pixel outside that band to match and every pixel inside it to be the fill value (437 band pixels on this input; 431 differ, the other 6 happen to extrapolate to 0).box_blur_grayruns at radius 2, where it is bit-exact. At radius 3, 3432 pixels differ, every one by exactly +1: jsfeat's1/49reciprocal undershoots and truncates, jsfeatNext divides exactly (#114). The loop is the same at either radius.
Inputs worth knowing. warp_perspective receives the inverse of the
perspective_4point_transform homography, because the warp maps destination to
source (as examples/sample_warp_perspective.html does). In the combined
compute_integral_image case the squared sum is a Float64Array: it reaches
about 6.7e9 on this noise, and an Int32Array would wrap identically on both
sides and still compare equal.
Result. Three series, each of four runs of npx vitest bench --run bench/imgproc.bench.ts after one discarded warm-up run. Series C is the one
to quote: it was taken on a quiet machine (see Conditions below). Series B,
on a loaded one, is kept beside it as a cross-check. Series A was taken before
the two input corrections above, so its warp_perspective and combined
compute_integral_image numbers measured the wrong input; it is not tabled
(its box_blur_gray read 1.27 / 2.31 / 1.18 / 1.84 jsfeat). "jsfeat" means
jsfeat was faster by that factor; unmarked numbers mean jsfeatNext was.
| case | series C (quiet), 4 runs | series B (loaded), 4 runs | reading |
|---|---|---|---|
grayscale |
1.03 jsfeat / 1.04 jsfeat / 1.00 / 1.16 jsfeat | 1.09 / 1.11 jsfeat / 1.04 / 1.07 jsfeat | noise |
pyrdown |
1.03 / 1.00 / 1.02 jsfeat / 1.03 jsfeat | 1.01 / 1.37 jsfeat / 1.01 / 1.14 | noise |
pyramid_t.build |
1.01 jsfeat / 1.01 jsfeat / 1.01 / 1.05 | 1.02 jsfeat / 1.08 jsfeat / 1.03 jsfeat / 1.06 jsfeat | noise |
compute_integral_image sum only |
1.12 / 1.11 / 1.10 / 1.12 | 1.08 / 1.15 / 1.14 / 1.07 | jsfeatNext slightly faster in every run of every series, under the floor; 1.10–1.11 on the bundle |
compute_integral_image sum + sqsum + tilted |
1.11 / 1.16 / 1.02 / 1.08 | 1.07 / 1.34 / 1.03 jsfeat / 1.06 | under the floor (one sign flip in B) |
sobel_derivatives |
1.03 jsfeat / 1.02 jsfeat / 1.07 / 1.01 | 1.03 / 1.05 jsfeat / 1.04 / 1.02 jsfeat | noise |
scharr_derivatives |
1.02 / 1.02 jsfeat / 1.00 jsfeat / 1.01 jsfeat | 1.02 / 1.41 jsfeat / 1.00 / 1.02 jsfeat | noise |
warp_perspective |
1.01 / 1.01 / 1.01 jsfeat / 1.01 jsfeat | 1.00 jsfeat / 1.02 / 1.02 / 1.02 | parity |
warp_affine |
1.01 jsfeat / 1.02 jsfeat / 1.02 jsfeat / 1.23 | 1.01 jsfeat / 1.02 jsfeat / 1.02 / 1.03 | noise (one outlier) |
canny |
1.04 / 1.04 / 1.02 jsfeat / 1.00 jsfeat | 1.02 jsfeat / 1.02 / 1.04 / 1.01 | parity: the per-call matrix_t does not show at this size |
equalize_histogram |
1.01 jsfeat / 1.03 / 1.02 / 1.04 jsfeat | 1.01 / 1.01 jsfeat / 1.00 / 1.11 | noise |
box_blur_gray radius 2 |
1.43 / 1.26 / 1.28 / 1.26 jsfeat | 1.31 / 1.15 / 1.20 / 1.23 jsfeat | finding: jsfeat faster in every run of every series |
skindetector |
1.00 / 1.00 / 1.02 / 1.05 jsfeat | 1.01 / 1.01 / 1.06 / 1.03, all jsfeat | noise |
Series C is markedly tighter than B: outside box_blur_gray, only three of its
48 other readings pass 1.15, each by a little and each in a single run
(grayscale 1.16 and warp_affine 1.23, both against the sign of their other
three runs, and the combined integral image 1.16). In series B, scharr,
pyrdown, orb.describe and the combined integral image each had a 1.3–1.5
outlier. That is the load showing, and why every reading above rests on the
direction across all runs, not on one value.
The finding: box_blur_gray is about 1.25× slower than jsfeat (1.26–1.43 in
the quiet series). It holds on the built bundle too (npm run bench:dist, three
runs after a warm-up, twice: 1.25 / 1.27 / 1.21 on the loaded machine and 1.24
/ 1.19 / 1.28 on the quiet one), so it is not the module-runner artefact. Not
diagnosed. The suspect is the #114 rewrite, which put a clamping ternary on
every read and Math.floor(sum / area) (a float division) on every write of the
inner loops, where jsfeat primes the window once and multiplies by a reciprocal.
Hoisting the clamps out of the interior and dividing exactly only where it
matters would be the first thing to try, under the parity tests and the #114
divergence tests. That is a src/ change, tracked in its own issue per #86:
#251.
Conditions, honestly. Intel Core i7-9700 (desktop, no battery), Windows 11, Node v24.21.0, Vitest 5.0.4. Load is the summed CPU time of every process over a 5 s window, as a share of all 8 cores.
- Series C (quiet): started only once two consecutive samples read under 20% (9.8% and 7.3%); 16.8% just before the first run and 2.9% after the last. Freshly rebooted, Windows Explorer restarted (it had been holding about 25% on its own) and OneDrive sync paused. The bundle re-check read 14.5% after it. Not a lab-idle machine (a browser and the Claude desktop app stayed open), but the quietest this file's imgproc numbers were taken on.
- Series B (loaded): 13% before, 28% after.
- Series A (loaded): about 18% before.
Reproduce:
npx vitest bench --run bench/imgproc.bench.ts --reporter=default --reporter=json --outputFile.json=bench-results/imgproc.json node scripts/bench-ratios.mjs bench-results/imgproc.json
gms.filter has no jsfeat counterpart, so bench/gms.bench.ts has no
"jsfeat (reference)" case and there is no jsfeatNext-vs-jsfeat ratio. It
follows the precedent of "yape06 costs N× fast_corners" instead: five
cases on the same inputs in one process, reported as "gms: <path> costs N×
matching". The question it answers is the one the milestone asks: does a GMS
pass cost more than the matching step it follows?
Workload: the tracker's. The 300 strongest FAST corners (threshold 20,
border 20) of each of two 640×480 views, ORB-described (with ic_angle),
matched with bfmatcher.knnMatch (k = 2) and ratio_test 0.75. The second
view is the first translated by (16, 8). The GMS cases filter the baseline's own
output. Detection, description and that output are all built at collection
time, outside the timed region; only knnMatch + ratio_test and
gms.filter run inside a bench callback.
Noise, not cornerScene (ruling R12). The workload was first tried on
cornerScene(640, 480) and its translated copy, as the property tests use. It
yields 36 FAST corners per view and 24 ratio-tested matches: nowhere
near the 300 keypoints and ~100+ matches a tracker frame produces, so GMS would
have looked trivially cheap because it had nothing to do. The bench therefore
uses two crops of one seeded noise canvas (noiseImage), 16 and 8 pixels apart,
which is an exact translation with real content at the edges of both views. It
gives 300 + 300 keypoints and 289 ratio-tested matches, and GMS keeps
219 of them on every path. Collection throws if either view falls below 300
keypoints, the matching below 100 matches, or a path keeps nothing.
Result. Five runs of npx vitest bench --run bench/gms.bench.ts after one
discarded warm-up run. "N× matching" is the mean latency of the path divided by
that of match: knnMatch k=2 + ratio_test 0.75 in the same run; the ms are the
median of the five runs.
| case | ms / call | N× matching, 5 runs | median |
|---|---|---|---|
match: knnMatch k=2 + ratio_test 0.75 (the baseline) |
2.56 | 1 | 1 |
gms: default |
0.174 | 0.068 / 0.069 / 0.066 / 0.068 / 0.064 | 0.068× |
gms: rotation |
1.21 | 0.487 / 0.472 / 0.453 / 0.472 / 0.448 | 0.47× |
gms: scale |
0.83 | 0.324 / 0.318 / 0.324 / 0.326 / 0.303 | 0.32× |
gms: rotation+scale |
5.97 | 2.288 / 2.392 / 2.250 / 2.381 / 2.195 | 2.29× |
Reading it:
- The default path, the one the tracker calls today, costs about one fifteenth of the matching step. The milestone's condition for raising it before release (a default path that costs more than the matching step) does not hold, by a factor of 15.
- Rotation (8 passes) and scale (5 passes) each cost less than the matching.
- Rotation + scale (40 passes) costs about 2.3× the matching step, 6.0 ms a call on this machine. It is the one path where GMS outweighs what it follows, and it is linear in passes × matches by construction. The choice of flags stays the caller's; it is not the default.
- The absolute milliseconds are this machine's. The ratios are intra-process, and the five runs spread by up to about ±5% on a path, which is inside the noise floor above: read them to one significant figure. Cost is linear in the number of matches (289 here); a poorer frame has fewer.
- The noise scene is idealised. The second view is an exact translation, so all 289 matches are true inliers, which a real frame's are not.
- The rotation paths are the load-sensitive ones. One busier run read rotation 0.42× and rotation+scale 2.10×.
Conditions, honestly. Intel Core i7-9700 (8 cores, a desktop with no
battery), Windows 11, Node v24.21.0, Vitest 5.0.4. The machine was not
idle: a browser, Docker Desktop's backend and the Claude desktop app were
running, and the CPU load read 9–34% before and after each run. The tight
spread above suggests the load moved the ratios little (both sides of every ratio
share the conditions, which is the point of using one), but this is not the
idle-machine measurement the rest of this file asks for. The same file against
the built bundle (npm run bench:dist, three runs after a warm-up) agrees:
0.065–0.068, 0.46–0.48, 0.31–0.32 and 2.24–2.34. An earlier five-run series on the
same source, taken before two collection-time-only edits to the file, gave the
same picture (0.064–0.072, 0.46–0.50, 0.31–0.33, 2.24–2.41).
Reproduce:
npx vitest bench --run bench/gms.bench.ts --reporter=default --reporter=json --outputFile.json=bench-results/gms.json
node scripts/bench-ratios.mjs bench-results/gms.json # "gms: default costs 0.068x match: ..."teblid.describe has no jsfeat counterpart either, so bench/teblid.bench.ts
has no "jsfeat (reference)" case; it reports "teblid pN costs N×
orb.describe" for the same keypoints in one process, three cases, the ORB
call being the baseline (the first task).
Workload. The 300 strongest FAST corners (threshold 20, border 20) of the
same seeded 640×480 noise image as the other detector benches, oriented with
orb.ic_angle and given size = 31 (ORB's patch diameter, which TEBLID reads
as the diameter of the described neighbourhood). Detection, orientation and the
output matrices are built at collection time; collection throws if fewer than
300 keypoints are found. Only the three describe calls run inside a bench
callback.
Result. Four runs of npx vitest bench --run bench/teblid.bench.ts after
one discarded warm-up run. "N× orb.describe" is the mean latency of the case
divided by that of orb.describe in the same run; the ms are the median of the
four runs.
| case | ms / call | N× orb.describe, 4 runs | median |
|---|---|---|---|
orb.describe (256 bits) (the baseline) |
2.49 | 1 | 1 |
teblid p256 |
3.90 | 1.55 / 1.62 / 1.55 / 1.54 | 1.6× |
teblid p512 |
6.91 | 2.74 / 2.90 / 2.73 / 2.73 | 2.7× |
Reading it:
- TEBLID p256 costs about 1.6×
orb.describe, p512 about 2.7×. p512 is about 1.75× p256 in the same run (1.76–1.79×): it evaluates twice the weak learners per keypoint. - p256 is the same descriptor size as ORB (32 bytes), so 1.6× is the like-for-like figure; p512 is 64 bytes per keypoint.
- Spread: p256 stays within ±2% and p512 within about ±3% across the four runs; read them to one significant figure. The ms are this machine's, the ratios are intra-process.
Conditions. Intel Core i7-9700 (8 cores, a desktop with no battery),
Windows 11, Node v24.21.0, Vitest 5.0.5, under the maintainer's rule of CPU load
under 20%. A background sampler read Win32_Processor LoadPercentage every
about 2 s during each run; a run started only after two consecutive readings
under 20%, and was kept only if every in-run sample was under 20%. One attempt
broke it (a 29% sample) and was discarded and repeated. Kept in-run samples (%):
warm-up 18/12/16, run 1 18/7/8, run 2 9/10/5, run 3 12/6/14, run 4 15/5/9. A run
lasts about 6 s, so that is three samples per run: the sampler is coarse, and the
bench process alone reads up to about 18%. Both sides of every ratio share the
conditions.
Reproduce:
npx vitest bench --run bench/teblid.bench.ts --reporter=default --reporter=json --outputFile.json=bench-results/teblid.json
node scripts/bench-ratios.mjs bench-results/teblid.json # "teblid p256 costs 1.6x orb.describe ..."freak.describe has no jsfeat counterpart either, so bench/freak.bench.ts
reports "freak costs N× orb.describe" for the same keypoints in one process,
with orb.describe (256 bits) as the baseline (the first task) and teblid p256
beside it for context.
Workload. The same 300 strongest FAST corners (threshold 20, border 20) of
the same seeded 640×480 noise image as the TEBLID bench. ORB and TEBLID are
oriented with orb.ic_angle; FREAK gets no angle, because it estimates its own
(that work is inside its timed call). There are two groups:
- size 31 (the plan's workload, ORB's patch diameter). FREAK's pattern does not fit around 168 of the 300 keypoints, so it drops them as OpenCV does and describes 132, while ORB and TEBLID describe all 300. The ratio in this group is therefore per call, not per keypoint.
- size 7, border 30. All 300 keypoints are kept by all three, so this is the like-for-like per-keypoint ratio, and the headline figure.
freak.describe compacts corners and writes angle, so it gets its own clones
of the keypoints and a fresh array copy before every iteration, in a
beforeEach hook that tinybench keeps outside the timed region. Collection
asserts the kept counts (132 and 300).
Result. Four runs of npx vitest bench --run bench/freak.bench.ts after one
discarded warm-up run. "N× orb.describe" is the mean latency of the case divided
by that of orb.describe in the same run; the ms are the median of the four runs.
| group | case | ms / call | N× orb.describe, 4 runs | median |
|---|---|---|---|---|
| size 7, 300 kept | orb.describe (256 bits) (the baseline) |
2.49 | 1 | 1 |
| size 7, 300 kept | teblid p256 |
4.05 | 1.63 / 1.61 / 1.62 / 1.63 | 1.6× |
| size 7, 300 kept | freak (512 bits) |
8.10 | 3.26 / 3.25 / 3.22 / 3.26 | 3.3× |
| size 31, FREAK keeps 132 | orb.describe (256 bits) (the baseline) |
2.49 | 1 | 1 |
| size 31, FREAK keeps 132 | teblid p256 |
4.24 | 1.71 / 1.69 / 1.71 / 1.70 | 1.7× |
| size 31, FREAK keeps 132 | freak (512 bits) |
4.11 | 1.66 / 1.66 / 1.63 / 1.65 | 1.7× per call |
Reading it:
- FREAK costs about 3.3×
orb.describeper keypoint (the size-7 group), or about 2× TEBLID p256. Per keypoint it is about 27 µs at size 7 and 31 µs at size 31 (4.11 ms / 132), so the size barely matters: the box means come from the integral image in constant time. - The extra cost over TEBLID has three sources, all inside the timed call: the
orientation pass (43 means and 45 weighted pairs per keypoint, which ORB and
TEBLID get from the separate
ic_angle), a second set of 43 means at the estimated orientation, and the pattern points computed on demand (acosand asinper point) instead of OpenCV's 8.5 MB lookup table (spec F1). FREAK is also 64 bytes per keypoint, twice ORB and TEBLID p256. - The size-31 "1.7×" is not a per-keypoint figure: FREAK describes 132 keypoints there against 300 for the others. Per keypoint it is about 3.7×.
- Spread: within ±1% across the four runs; read the ratios to two significant figures. The ms are this machine's, the ratios are intra-process.
Resident memory. 2266 B of module-level tables (the 512 pairs as Int16,
1024 B, and as two Uint8 point-index arrays, 1024 B; the 45 orientation pairs,
90 B; the ring radii and sigmas, 128 B). Per call, about 2 KB of constants and
scratch (1384 B of scaling factors, pattern sizes and weights; 688 B of scale-0
points; the 43 means), 4 B per keypoint for its scale index, and the integral
image, a Float64 buffer of (cols + 1) * (rows + 1) entries (about 2.5 MB at
640×480) borrowed from the shared pool and returned after the call.
Conditions. Intel Core i7-9700 (8 cores, a desktop with no battery),
Windows 11, Node v24.21.0, Vitest 5.0.5, under the maintainer's rule of CPU load
under 20%, with the same sampler as the TEBLID bench: Win32_Processor
LoadPercentage every about 2 s; a run started only after two consecutive
readings under 20% and was kept only if every in-run sample was under 20%.
17 attempts broke it (in-run maxima 21–35%) and were discarded and repeated; an
earlier session on 2026-10-30 discarded 59 attempts on a busier machine and
measured nothing. Kept in-run samples (%), 2026-11-03: warm-up 11/14/13/12,
run 1 10/3/15/17, run 2 15/11/14/8, run 3 17/13/12/8, run 4 16/9/8/14. The bench
process alone reads up to about 18%. Both sides of every ratio share the
conditions.
Reproduce:
npx vitest bench --run bench/freak.bench.ts --reporter=default --reporter=json --outputFile.json=bench-results/freak.json
node scripts/bench-ratios.mjs bench-results/freak.json # "freak (512 bits) costs 3.3x orb.describe ..."- All inputs come from the deterministic generators in
tests/properties/helpers.ts(seeded PRNG), so runs are reproducible. - Both sides get identical data — the oracle matrix is filled from the same buffer, never regenerated.
- ORB detects its keypoints once, outside the timed function, so the measurement is
describe()alone rather thandetect()+describe(). Keypoints use border 20 so no sampling pattern crosses the image edge (#110) and both implementations do identical work. - GMS also uses noise rather than
cornerScene(36 corners and 24 matches: too little for GMS to have anything to do), cropped twice from one canvas for the translated view; see the GMS section above. - ORB uses noise rather than
cornerScene: the latter is built for the correctness tests and yields only ~27 keypoints at border 20, which would time call overhead rather than the algorithm. Noise yields tens of thousands, capped at 500 to match a realistic AR frame.
Two different things, split on purpose.
CI.yml runs npm run bench:smoke on every push and PR. It loads every bench
file and executes its module-level and describe bodies, then skips the
timed callbacks (every test body, i.e. the bench(...).run() calls —
the run passes --testNamePattern="__collect_only__", which matches nothing).
It answers "do the benchmarks still work?", never "how
fast are they" — nothing is measured, so runner noise is irrelevant and it can
safely fail the build.
It earns its place because bench/ is otherwise untouched by CI: npm test
includes only tests/**, so a src/ refactor can rot a bench file in silence.
That is not hypothetical — every real breakage this suite has had lived in
collection-time code: undersized keypoint pools, a failed count assertion, a
leaked Math.random stub, a comparator that made qsort not sort.
That is also why the Vitest 5 shape keeps each case's setup in the describe
body and puts nothing but the two bench(...).run() calls in the test.
Moved into the test body, the same setup would be skipped by the name filter
and the smoke check would pass without having checked anything.
CI.yml also runs npm run typecheck, which uses tsconfig.check.json to
cover bench/ as well as src/. The project's own tsconfig.json includes
only src/**/* because it drives vite-plugin-dts and the published types/
output — so a plain tsc -p tsconfig.json reports clean while never looking at
a bench file. A genuine type error survived several PRs that way (#157).
.github/workflows/bench.yml is workflow_dispatch only and exists for one
purpose: looking at the ratios without running them locally. It cannot fail a
build, and it does not feed the history.
That is a judgement about trust, not caution. A shared runner is the least trustworthy environment this project measures in — the ~1.15x noise floor above was established on a quiet local machine, and nobody has measured what it is on a runner. Gating on that would mean widening the threshold until it stopped shouting, leaving a check that can no longer detect anything.
So: do not open a finding from a CI run. Reproduce it locally, idle, first.
Results are uploaded as an artifact, retained 90 days.
Artifacts expire, so they are not a record. bench/history.jsonl is: one
appended line per run, never rewritten, holding the ratios and nothing else.
{
"date": "2026-08-22T17:06:00.951Z",
"version": "0.13.0",
"sha": "3b475f382e1c",
"env": { "ci": false, "node": "v22.21.1", "platform": "win32",
"cpu": "11th Gen Intel(R) Core(TM) i7-11800H", "cores": 16 },
"geomean": 1.0967,
"cases": { "matmath.invert_3x3": 1.0891 }
}cases holds the signed speedup — above 1.0 means jsfeatNext is faster,
below means jsfeat is — so records aggregate without a separate direction field.
The environment block is not decoration. The A/B ratio cancels most machine
differences but demonstrably not all: yape06 measured ~1.3x on one checkout
and ~1.04x on another. Two records are only comparable if their env matches,
and a reader cannot tell without it. OpenCV's
cvbenchmark commits its results the
same way, putting the CPU in the filename rather than pretending numbers
transfer between machines.
The measurement protocol changed with Vitest 5 (#219): each case went from
500 ms plus a 100 ms warm-up to 1000 ms plus 250 ms. Records since this note
carry env.vitest; older ones do not, and their date tells which side of the
change they are on.
geomean is the geometric mean of the signed speedups — the same aggregation
cvbenchmark uses. Geometric, not arithmetic, because these are ratios: 2x
faster and 2x slower must cancel to 1.0, and only the geometric mean does that.
Read it as a coarse indicator, never as a finding: it averages a 3x outlier
on a tiny function together with cases that barely move, so a per-case
regression can hide inside a healthy-looking mean. The table is the data.
Append a local run with:
npm run bench:ratios
Only local runs feed this file. The CI workflow does not append to it at all — deliberately. Its numbers come from a shared runner, which is precisely the environment whose measurements are not worth keeping forever; and appending from CI would need write permissions on a workflow anyone can dispatch. The record is built from idle-machine local runs, because those are the ones worth recording.
Intra-library groups (bench/gms.bench.ts) are never recorded here: the history is jsfeatNext-vs-jsfeat speedups, and a cost relative to the matching step is a different quantity.
Raw hz are never committed — see the section below.
The noise floor above is our own measurement, on this machine. For the general problem of benchmarking on managed runtimes and on CI:
benchmark-action/github-action-benchmark— the reference project for running benchmarks in CI. Worth noting that its default regression alert threshold is 200% (a 2× slowdown): a default that conservative is itself a statement about how noisy hosted runners are.- tinybench — what
vitest benchuses underneath. Explains thermeandsamplescolumns. Notermeis the error within one measurement (ours runs ~1–3%, comfortably low); the variance between runs is a different and much larger thing — that is what the noise floor above measures. - Vitest benchmarking docs — the
benchtest-context fixture, its options, and the module-runner overhead section behind the Vitest 5 artefact above. - Georges, Buytaert & Eeckhout, "Statistically Rigorous Java Performance Evaluation" (OOPSLA 2007) — the classic treatment of why single runs on a JIT runtime mislead: warm-up, non-deterministic GC, the need for repeated measurements. Written for the JVM, but every problem it describes applies to V8.
GitHub does not guarantee reproducible performance on hosted runners — it specifies the hardware, not isolation from neighbours. The absence of that guarantee matters more than any particular percentage.