Replace decimal.Decimal with dual int64/float64 number representation#138
Merged
Replace decimal.Decimal with dual int64/float64 number representation#138
Conversation
Removes the shopspring/decimal dependency and replaces all number handling with a dual int64/float64 internal representation (Lua 5.3 style). Integer operations stay int64, float operations use float64, and division always promotes to float (Python 3 style). This eliminates the massive allocation overhead from arbitrary-precision math in hot loops — the primary performance bottleneck for game engine workloads in Lumen. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shopspring/decimaldependency entirelydecimal.Decimalnumber type with a dualint64/float64internal representation (Lua 5.3 style)int64; any operation involving a float promotes tofloat645 / 2→2.5, like Python 3)floor()andround(0)return integersMotivation
decimal.Decimaluses arbitrary-precision math backed bybig.Int, meaning every number literal and every arithmetic result allocates on the heap. In game engine workloads (e.g. Lumen's tilemap renderer doing ~15,000 iterations/frame), this is the dominant performance bottleneck.float64is more than sufficient for games, and a separatedecimalmodule can be added later for financial/scientific precision when needed.Changes
object/number.go— newNumberstruct withi int64,f float64,isFloat bool; constructorsNewInt/NewFloat; arithmetic, comparison, and math methodsast/number.go—IntValue int64,FloatValue float64,IsFloat boolfieldsparser/number.go— parses integers withstrconv.ParseInt, floats (.ore) withstrconv.ParseFloatevaluator/— updated number eval, postfix, prefix, index, for-in, assignobject/— updated string, list, map, object helperslibrary/modules/— updated math, time, random, osTest plan
go test ./...passes🤖 Generated with Claude Code