13:30
-
14:10
-
14:10
Day 2
Writing an ultrafast Lua/JSON encoder+decoder as a LuaJIT module
<p>JSON is one of the most popular data exchange formats. Parsing routines for it exist in every modern programming languages, either built-in, or included in popular libraries such as <a href="https://rapidjson.org/">RapidJSON</a> for C++ or <a href="https://docs.rs/json/latest/json/">json</a> for Rust.</p>
<p>The task of conversion between JSON strings and <a href="https://lua.org/">Lua</a> objects has been solved plenty of times before, but either the solutions are not focused on performance, or the parsers are too strict for the "relaxed" format we use at <a href="https://www.beamng.com/game/">BeamNG</a>.</p>
<p>What if we want to have the fastest Lua table <-> relaxed JSON conversion possible? We came up with a highly optimized LuaJIT code we use for handling JSONs at <a href="https://www.beamng.com/game/">BeamNG</a> since a few years. But there is a way to go further -- hacking on the C source code of the interpreter itself to add compiled built-in JSON support. How much extra performance can we squeeze out by going a level deeper?</p>
<p>Get ready for juicy benchmarks and an optimization story from a real usage perspective.</p>