This is the research playbook for the ms performance-optimization project. It tells agents what to optimize, what they can touch, and what constraints to respect. Read this before every experiment.
required_confirmations: 0 metric_tolerance: 3 metric_direction: lower_is_better lead_github_login: alanzabihi auto_approve: true assignment_timeout: 24h review_timeout: 12h min_queue_depth: 5 max_queue_depth: 10
Reduce the execution time of ms library operations, measured in milliseconds
and percent, while preserving every observable behavior.
- Primary — parse_ms: 2M calls to
parse()over 30 diverse inputs (short units, long units, decimals, negatives, bare numbers). Baseline ~155 ms. Optimize this. - Guard — format_ms: 2M calls to
format()alternating short/long over 18 diverse inputs. Baseline ~30 ms. Must not regress by more than 10%.
An improvement must reduce parse_ms by at least 3 ms. format_ms may not regress by more than 3 ms compared to its baseline.
Secondary constraint: correctness. The harness's parse_fp must equal
parse:3de2a72832c8310a and format_fp must equal
format:3557e89b64e4b470. All 167 existing tests must pass on both Node and
Edge runtime environments.
parse() at ~77 ns/call is 5× slower than format() at ~15 ns/call. The
bottleneck is a single complex regex with named capture groups that runs on
every call. Format is already a chain of comparisons and Math.round — little
room to improve. Optimizing parse yields the most absolute gain; format is the
guard because regressions there would be gratuitous since it shares no code
path with parse.
src/index.ts— the library source, includingparse,parseStrict,format,ms, and the module-level constants and helper functions (fmtShort,fmtLong,plural). Types and exported signatures must not change.
.polyresearch/— the reproducible environment (if/when present)POLYRESEARCH.md— the coordination protocolPROGRAM.md— this research playbookPREPARE.md— the evaluation setupresults.tsv— maintained by the lead onmainbench/— the benchmark harnesssrc/*.test.ts— the test suitenode_modules/— dependenciespackage.json— dependency manifest and scriptstsconfig.json,biome.json,jest.config.ts,tsdown.config.ts— build and tooling config.github/— CI and GitHub configREADME.md,LICENSE,assets/
- Public API and exported types are frozen. The exports
ms,parse,parseStrict,format, andStringValuemust keep their current signatures and runtime behavior for all inputs covered by the tests and the harness fingerprint set. - No new dependencies (neither runtime nor dev).
- Runtime targets unchanged — must keep working on Node >= 20 and under
@edge-runtime/jest-environment. - Fingerprint equality is exact. Any change that affects
parse_fporformat_fpis a hard reject, even if the test suite still passes. - format is a guard, not a target. It may regress by up to 10% on its own baseline, but a regression that does not correspond to a parse_ms win is almost always a sign of accidental damage and will be rejected.
A candidate is rejected if any of:
parse_fporformat_fpchanges.format_msregresses more than 10% (or more than 3 ms absolute).pnpm run lintfails.pnpm run typecheckfails.pnpm run buildfails.pnpm run test:nodejsfails.pnpm run test:edgefails.- Public API or exported types change.
- New runtime dependencies are added.
- Any file outside the CAN modify list is touched.
These are suggestions — pursue whatever approach moves the metric, as long as invariants hold.
- Hand-rolled parser replacing regex: eliminate the regex engine from the hot path; use charCode comparisons and bit-masking for case folding.
- Fast integer fast path: most inputs are integers like
"1h","30s","7d". Accumulate digits withc - 48and fall back toparseFloatonly when a.is seen. - CharCode unit dispatch: replace the 30-case switch with a dispatch on
first character plus length, avoiding
.toLowerCase()altogether. - Simplified regex: drop named capture groups and the
iflag; normalize case with one.toLowerCase()call on the whole string before matching. - Combined fast path: single-pass parser doing sign, number, unit, and dispatch without any intermediate allocation.
bench/harness.mjs — runs with plain node, no dependencies. Prints four
tab-separated lines:
parse_ms <float>
format_ms <float>
parse_fp parse:<hex>
format_fp format:<hex>