TOML Fortran 0.3.0

Thanks for testing this. Looks like you kept the pruning step for removing type annotations for the toml-test JSON format (this one only uses strings + type annotations). The transformation of the whole data structure to remove the type hints, even if non are present, is rather expensive.

Running the repository (c9d72db, GFortran 12, Intel i7-6500U CPU @ 2.50GHz) gives the following baseline for me

      read file to a string :   0.0011  seconds
               json_fortran :   0.2133  seconds
                       fson :   1.5379  seconds
                      rojff :   0.2757  seconds
                      tomlf :   0.9108  seconds

Without the unneeded transformation the timings look somewhat different.

      read file to a string :   0.0011  seconds
               json_fortran :   0.2107  seconds
                       fson :   1.5152  seconds
                      rojff :   0.2744  seconds
                      tomlf :   0.2704  seconds

Profiling the modified test program with VTune shows that the JSON parsing is currently spending about one third of the runtime on the deep-copy of the data structure to remove the artificial top-level table:

I think this can be avoided by giving the toml_table type a possibility to drop a value and return the allocation, which can than returned as polymorphic toml_value rather than as toml_table, being more appropriate for the JSON format.

In any case, TOML Fortran is not a JSON parsing library, it just happens to need a JSON parser. Since the JSON grammar is much easier than the TOML one, it makes for a shorter tutorial to teaching the idea of the lexer in the library.


Edit:

After a bit of tinkering (see Refactor storage structure for tables and arrays by awvwgk · Pull Request #108 · toml-f/toml-f · GitHub) I’m now actually able to barely outperform JSON Fortran on its own benchmark:

      read file to a string :   0.0012  seconds
               json_fortran :   0.2172  seconds
                       fson :   1.5760  seconds
                      rojff :   0.2866  seconds
                      tomlf :   0.2127  seconds

The deep-copy of a data structure representing 2MB of JSON is indeed quite demanding and shouldn’t be done if it can be avoided. Still, I find it amazing that it is actually possible to do a deep-copy with nothing but a simple assignment in Fortran (if the derived types contain only allocatables like in TOML Fortran).

2 Likes