Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOML support (tomlkit) is very slow #184

Closed
intelfx opened this issue Mar 7, 2024 · 3 comments
Closed

TOML support (tomlkit) is very slow #184

intelfx opened this issue Mar 7, 2024 · 3 comments

Comments

@intelfx
Copy link

intelfx commented Mar 7, 2024

Parsing a ~700 KiB TOML file with tomlq takes 20s on my ~4GHz laptop:

$ curl -fsSL 'https://static.rust-lang.org/dist/channel-rust-nightly.toml' | wc -c | bscalc -H  
753.85 KiB

$ time curl -fsSL 'https://static.rust-lang.org/dist/channel-rust-nightly.toml' | tomlq >/dev/null
curl -fsSL 'https://static.rust-lang.org/dist/channel-rust-nightly.toml'  0,02s user 0,00s system 3% cpu 0,645 total
tomlq > /dev/null  21,56s user 0,08s system 97% cpu 22,256 total

Perhaps consider a different toml library if style-preserving features (i. e. roundtrip output) are not required?

@kislyuk
Copy link
Owner

kislyuk commented Mar 8, 2024

Thanks for letting me know.

I'm beginning to sour on TOML as a file format. I think it's not a great file format. I'm curious if your use case involves writing toml or just extracting values from it? I wonder if I should just discontinue support for writing TOML (toml -t) and only support reading. That would make the choice of library obvious - https://docs.python.org/3/library/tomllib.html which is approximately 70 times faster on my system.

@intelfx
Copy link
Author

intelfx commented Mar 8, 2024

I'm curious if your use case involves writing toml or just extracting values from it?

No, just extracting the values — actually, the example I gave above is my use-case.

I'm beginning to sour on TOML as a file format. I think it's not a great file format.

In fact, I very much share your opinion :-) Unfortunately, the Rust ecosystem uses it quite widely (not to say of Python's very own PEP 517 and descendants), and I need to integrate certain processes with it, so here we are.

That would make the choice of library obvious - https://docs.python.org/3/library/tomllib.html which is approximately 70 times faster on my system.

Yes, but it should be noted that this module is 3.11+. So there likely has to be some sort of a fallback at least for the time being.

@kislyuk
Copy link
Owner

kislyuk commented Apr 15, 2024

I addressed this by using tomllib when available.

@kislyuk kislyuk closed this as completed Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants