Separate Integer and String Key Tables vs Mixed Table for Large Lua Datasets
0 reputation · 05 Oct 2024, 20:37 UTC
When working with large datasets in Lua, developers must choose between storing all keys—both integer indices and string identifiers—in a single table or splitting them into two distinct tables, one for the array part and one for the hash part. The goal is to minimize memory overhead and garbage‑collection pressure while preserving O(1) lookup performance for both key types.
Constraints include the known degradation that occurs when integer and non‑integer keys coexist in the same table, which can cause the table’s internal array and hash parts to interleave, increase fragmentation, and trigger more frequent resizes. Additionally, the Lua garbage collector’s stop‑the‑world pauses may be affected by the number and size of allocated tables.
Does separating integer and string keys reduce overall memory consumption? Does it improve iteration speed over the array part? Does it lead to shorter or fewer GC pause times?