Skip to content

Parsing is slow for large arrays #278

@BrouxtForce

Description

@BrouxtForce

I have recently tried to switch from toml++ (seeing as toml++ does not preserve whitespace or comments), but toml11 is too slow at parsing large arrays (it seems that computational complexity is O(N2) with array size). For whatever reason, I have cursed myself with these long arrays in my TOML files, so now my application stalls for several seconds when I load such a file.

Here's a simple example with a array with length 5000:

#include <iostream>
#include <sstream>
#include <chrono>
#include <toml.hpp>

int main(int argc, char** argv)
{
    std::stringstream ss;

    ss << "[Numbers]\narray = [";
    for (int i = 0; i < 5000; i++)
    {
        if (i != 0) ss << ", ";
        ss << i;
    }
    ss << "]\n";

    std::cout << ss.str() << std::endl;;

    std::cout << "Start parsing..." << std::endl;

    auto start = std::chrono::steady_clock::now();
    toml::value input = toml::parse_str(ss.str());
    auto end = std::chrono::steady_clock::now();

    std::cout << "Finished parsing!" << std::endl;
    std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions