English

Mathematical Models to Analyze Lua Hybrid Tables and Why They Need a Fix

Discrete Mathematics 2023-12-07 v2

Abstract

Lua (Ierusalimschy et al., 1996) is a well-known scripting language, popular among many programmers, most notably in the gaming industry. Remarkably, the only data-structuring mechanism in Lua are associative arrays, called tables. With Lua 5.0, the reference implementation of Lua introduced hybrid tables to implement tables using both a hashmap and a dynamically growing array combined together: the values associated with integer keys are stored in the array part, when suitable, everything else is stored in the hashmap. All this is transparent to the user, who gets a unique simple interface to handle tables. In this paper we carry out a theoretical analysis of the performance of Lua's tables, by considering various worst-case and probabilistic scenarios. In particular, we uncover some problematic situations for the simple probabilistic model where we add a new key with some fixed probability p>12p>\frac12 and delete a key with probability 1p1-p: the cost of performing T such operations is proved to be Ω(TlogT)\Omega(T\log T) with high probability, where linear complexity is expected instead.

Cite

@article{arxiv.2208.13602,
  title  = {Mathematical Models to Analyze Lua Hybrid Tables and Why They Need a Fix},
  author = {Conrado Martínez and Cyril Nicaud and Pablo Rotondo},
  journal= {arXiv preprint arXiv:2208.13602},
  year   = {2023}
}

Comments

Long version of https://doi.org/10.1007/978-3-031-22105-7_34

R2 v1 2026-06-25T02:03:25.155Z