Skip to content

Widen int64 cache and compare integers without float conversion - #375

Merged
mattn merged 1 commit into
masterfrom
perf-int-cache-compare
Jul 9, 2026
Merged

Widen int64 cache and compare integers without float conversion#375
mattn merged 1 commit into
masterfrom
perf-int-cache-compare

Conversation

@mattn

@mattn mattn commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Two changes for arithmetic-heavy scripts:

  • The int64 value cache covered -1..256, so loop counters and sums beyond that boxed a new value on every operation. It now covers -1..4095 (~130KB resident).
  • The <, <=, >, >= operators converted both sides to float64 even for integer operands. Integers are now compared as int64, which is faster and also fixes wrong results above 2^53 where float64 loses precision (e.g. 9223372036854775807 > 9223372036854775806 returned false).

BenchmarkLoop: 37.2us -> 35.3us, allocations 91 -> 23.

@mattn
mattn merged commit 6c9a466 into master Jul 9, 2026
12 checks passed
@mattn
mattn deleted the perf-int-cache-compare branch July 10, 2026 00:43
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