Unsolicited Programming Suggestion (#UPS): always consider if you've got the right tool for the problem. Example: I was writing a #Python app that needed to import a #Lua file containing a data structure – a tree built using tables, like this:

DATA = {
["node1.1"] = {
["node2.1"] = some_value,
["node2.2"] = other_value,
},
["node1.2"] = {

etc. etc. The structure had several thousand nodes.

My first attempt: oh, there is this luadata Python module, I can use it!
… parsing my Lua file took several seconds. Not microseconds. Not milliseconds. Seconds. On my Ryzen 7 9700X.

Then I noticed that structure is essentially the same as the Python dict I'm going to build, modulo syntactic details, so maybe just use regexp to convert the syntax to pythonic:

{
"node1.1" : {
"node2.1" : some_value,
"node2.2" : other_value
},

and then parse it using ast.literal_eval() (for security reasons I didn't want to simply use eval instead of ast's parser, as the Lua file came from external source). Wow, much faster, ~0.2 s, but still…

Then it dawned on me – convert to #JSON and use json.loads(). Apparently, json's parser is more efficient than ast's parser because JSON syntax is much simpler than generalized Python literal syntax. Got down to 20 ms, something I can live with.

@blotosmetek All the builtin ways for python to deserialize its own syntax are criminally slow. The real difference is how much is native code and how much is extra code to deal with dynamic programming possibilities that never happen with just data.

https://github.com/matthewdeanmartin/hissbytenotation?tab=readme-ov-file#deserialization-benchmark--1000-iterations

GitHub - matthewdeanmartin/hissbytenotation: Library to make it easy to use python literal syntax as a data format

Library to make it easy to use python literal syntax as a data format - matthewdeanmartin/hissbytenotation

GitHub