Skip to content

perf: three small speed-ups to the TypeScript implementation, and a corpus benchmark - #98

Open
hearnadam wants to merge 4 commits into
devfrom
perf/ts
Open

hearnadam wants to merge 4 commits into
devfrom
perf/ts

Conversation

@hearnadam

Copy link
Copy Markdown
Contributor

Three small speed-ups to the TypeScript implementation and a benchmark to measure them with. Source change: 3 files, +23/−7.

  • script/corpus.ts: runs the 16 short programs of rust/bench/corpus (a few tool calls and the glue between them) against a host that answers at once, and reports median microseconds by phase: compile, a fresh run's setup, the program. bun run script/corpus.ts rust/bench/corpus.
  • A function sets its name and length without define's checks. A run makes several hundred built-in functions before its program starts, each through two calls of define. Setup about 78 → 72 µs.
  • The prelude's install paths are split once per process, not for every run. Setup about 72 → 64 µs.
  • String methods skip the conversion list for a string receiver and plain arguments. Each built two arrays and a closure to ask whether anything needed converting. The grep program about 90 → 64 µs, line counting about 187 → 167 µs.

Corpus total about 1,918 → 1,750 µs (9%). These are wall-clock medians taken on a busy machine, so approximate.

Not changed: setup is still about 60% of the corpus, nearly all of it making the built-ins for each run. Not making them (lazy groups, or reusing a runtime) is a structural change and is left alone here.

bun test and bun run test:roundtrip pass (1,648 tests).

The TypeScript side of rust/bench/examples/corpus: the same 16 short programs
against a host that answers at once, as median microseconds of compile, a fresh
run's setup, and the program. On dev: setup is 78 of the 80 µs return 1 takes,
63% of the corpus.
A run makes several hundred built-in functions before its program starts, each
through two calls of define, which checks for an array, an intrinsic and a
guard: none of which a function just made can be. script/corpus.ts: setup 78
to about 72 µs.
Each run split every prelude function's name and walked its path with a slice
and a reduce. script/corpus.ts: setup about 72 to about 64 µs.
…nd plain arguments

Every String.prototype method built two arrays and a closure to ask whether
anything needed converting, before doing its work. A string receiver whose
hinted arguments are not objects, which is nearly every call, goes straight to
it. script/corpus.ts: the grep program about 90 to 64 µs, line counting about
187 to 167 µs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant