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

Extremely slow decoding of escaped string fields #535

Open
peterebden opened this issue Feb 18, 2025 · 0 comments
Open

Extremely slow decoding of escaped string fields #535

peterebden opened this issue Feb 18, 2025 · 0 comments

Comments

@peterebden
Copy link

I've got a case of a large (~465MB) JSON file which happens to contain a bunch of strings with escaping in them. This decodes fairly readily using encoding/json in ~3.5s or so, but takes > 10min with go-json (long enough that I initially thought it was hanging, until I got further into the issue).

The issue seems to be here: https://github.com/goccy/go-json/blob/master/internal/decoder/string.go#L190
i.e. every time it hits an escaping backslash it shuffles the entire buffer (which seems to have eagerly read the entire payload) by one character, which is gonna be quadratic in the file size & hence pretty slow.

I'll attach a benchmark with a minimal reproduction. I'm unfamiliar with this library though so a bit less sure on the best approach to fix right now.

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

No branches or pull requests

1 participant