Skip to content

perf: precompute time unit constants#293

Open
wyf027 wants to merge 1 commit into
vercel:mainfrom
wyf027:perf/precompute-time-constants-271
Open

perf: precompute time unit constants#293
wyf027 wants to merge 1 commit into
vercel:mainfrom
wyf027:perf/precompute-time-constants-271

Conversation

@wyf027

@wyf027 wyf027 commented May 26, 2026

Copy link
Copy Markdown

Summary

  • Replace runtime multiplication chains with precomputed millisecond literals for m, h, d, w, y, and mo
  • Keeps behavior identical while avoiding repeated arithmetic at module load

Fixes #271

Test plan

  • npm test — 167 passing

Replace runtime multiplication chains with literal millisecond values
for each unit constant.

Fixes vercel#271
@wyf027 wyf027 force-pushed the perf/precompute-time-constants-271 branch from 2e12d33 to c16fd97 Compare May 26, 2026 05:06
@aabbdev

aabbdev commented May 28, 2026

Copy link
Copy Markdown

V8 already do constant folding, so it's useless, no perf improvement

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.

Unnecessary math

2 participants