-
Notifications
You must be signed in to change notification settings - Fork 168
Add CPK.DB.Gi - GameInfo fast and memory-optimized subtitute #12275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
6eece6a to
4944ea2
Compare
f0d940d to
64b7a7e
Compare
I didn't expect this one to throw. |
@azum4roll |
|
So only when the table is missing the ID column, not when you try to get a nil row. |
@azum4roll Exactly, but not only for the ID column but any string or number primary column, it doesn't have to be named For example The logic goes like this.
|
This PR introduces
Gi, compact, immutable, read-only in-memory representation ofGameInfowith identical API.Why:
The built-in GameInfo eagerly materializes Lua tables per row, leading to high memory usage, GC pressure, and slow iteration on large tables. Since the underlying database is static, a more aggressive and optimized representation is both safe and practical.
What improved:
~8xlower static memory usage across allGameInfotablesO(1)indexed access by primary key (numeric or string)How:
Each table is assembled once by analyzing column statistics and selecting the cheapest possible storage strategy per column (constants, bit-packed booleans, packed integer ranges, dictionaries, or sparse maps).
All row data is encoded into flat arrays, primary-key indices are built upfront, and rows are exposed as immutable views that decode values lazily on access.
Future direction:
Giis intended to progressively replace the built-in GameInfo where possible,serving as a safer and significantly more performant alternative with compatible access patterns.
Low-level design notes (for reviewers)
Gi internal design (CLICK TO EXPAND)
Assumptions:
Assembly pipeline:
Column encodings:
CONST– single value for entire columnBOOL– 1 bit per rowPINT– packed integer rangeDICT– dictionary-encoded values, bit-packedSPARSE– dominant default + sparse overridesSCALAR– one Lua slot per row (fallback)Memory optimizations:
Access model:
O(1)Condensed benchmark results
Test methodology summary:
CLICK TO EXPAND
os.clock(); memory measured viacollectgarbage("count")GameInfovsGicorrectness validated by row-by-row value comparison across all tables.Giimplementation verified by re-running benchmarks to exclude false positives (memory leaks).Benchmark results / actual numbers
CLICK TO EXPAND
🛠️ Fixes and improvements
CLICK TO EXPAND
🛠️ Direct access for single primary-key tables
Giallows direct indexed access.GameInfo.🛠️ Boolean values supported in table-based filters
🛠️ Parameterized SQL filters supported
CLICK TO EXPAND
These changes are intentional and designed to surface bugs that were previously silent
(e.g. typos, invalid indexes, or nonexistent schema elements).
💡 New features
CLICK TO EXPAND
defined in the table schema, not whether the value in the specific row is non-nil:
P.S.
Special thanks to @schnetziomi5, @azum4roll, @axatin