Skip to main content

A Probabilistic Model Revealing Shortcomings in Lua’s Hybrid Tables

  • Conference paper
  • First Online:
Computing and Combinatorics (COCOON 2022)

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, is an associative array called a table. With Lua 5.0, the reference implementation of Lua introduced hybrid tables to implement tables using both a hash table and a dynamically growing array combined together: the values associated with integer keys are stored in the array part, when suitable. All this is transparent to the user, which has 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>\frac{1}{2}\) and delete a key with probability \(1-p\): the cost of performing T such operations is proved to be \(\varOmega (T\log T)\) with high probability, instead of linear in T.

The work of the first author has been supported by funds from project MOTION (Project PID2020-112581GB-C21) of the Spanish Ministry of Science & Innovation MCIN/AEI/10.13039/501100011033.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 69.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 89.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://github.com/python/cpython/blob/main/Objects/listsort.txt.

  2. 2.

    https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html.

  3. 3.

    From the Portuguese “lua”, meaning moon.

  4. 4.

    We will sometimes also refer to the hashmap as the hash table.

  5. 5.

    All detailed descriptions in the remaining of the paper and our analysis refer to version 5.4.4 of Lua (the most recent).

  6. 6.

    We use the Greek letter \(\nu \) for consistency with the other notation in this section, \(\nu _t\) corresponds to \(N \) when no deletions occur.

  7. 7.

    This is done in linear time by counting the number of integer keys between \(2^{\ell -1}\) and \(2^{\ell }\) for each \(\ell \), for \(1\le 2^\ell \le M\).

References

  1. Auger, N., Jugé, V., Nicaud, C., Pivoteau, C.: On the worst-case complexity of TimSort. In: Azar, Y., Bast, H., Herman, G. (eds.) 26th Annual European Symposium on Algorithms, ESA 2018, 20–22 August 2018, Helsinki, Finland. LIPIcs, vol. 112, pp. 4:1–4:13. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2018)

    Google Scholar 

  2. Buss, S., Knop, A.: Strategies for stable merge sorting. In: Chan, T.M. (ed.) Proceedings of the 30th ACM-SIAM Symposium on Discrete Algorithms, SODA 2019, San Diego, California, USA, 6–9 January 2019, pp. 1272–1290. SIAM (2019)

    Google Scholar 

  3. de Gouw, S., Rot, J., de Boer, F.S., Bubel, R., Hähnle, R.: OpenJDK’s Java.utils.Collection.sort() is broken: the good, the bad and the worst case. In: Kroening, D., Păsăreanu, C.S. (eds.) CAV 2015. LNCS, vol. 9206, pp. 273–289. Springer, Cham (2015). https://doi.org/10.1007/978-3-319-21690-4_16

    Chapter  Google Scholar 

  4. Ierusalimschy, R., de Figueiredo, L.H., Filho, W.C.: Lua—an extensible extension language. Softw. Pract. Exp. 26, 635–652 (1996)

    Article  Google Scholar 

  5. Ierusalimschy, R., de Figueiredo, L.H., Filho, W.C.: The implementation of Lua 5.0. J. Univers. Comput. Sci. 11(7), 1159–1176 (2005)

    Google Scholar 

  6. Ierusalimschy, R., de Figueiredo, L.H., Filho, W.C.: Lua programming gems. Lua.Org (2008)

    Google Scholar 

  7. Knuth, D.E.: The Art of Computer Programming: Sorting and Searching, vol. 3, 2nd edn. Addison-Wesley (1998)

    Google Scholar 

  8. Martínez, C., Nicaud, C., Rotondo, P.: A probabilistic model revealing shortcomings in Lua’s hybrid tables (2022). https://arxiv.org/abs/2208.13602

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Pablo Rotondo .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Martínez, C., Nicaud, C., Rotondo, P. (2022). A Probabilistic Model Revealing Shortcomings in Lua’s Hybrid Tables. In: Zhang, Y., Miao, D., Möhring, R. (eds) Computing and Combinatorics. COCOON 2022. Lecture Notes in Computer Science, vol 13595. Springer, Cham. https://doi.org/10.1007/978-3-031-22105-7_34

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-22105-7_34

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-22104-0

  • Online ISBN: 978-3-031-22105-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics