Skip to content

Extremely slow decoding of escaped string fields #535

Open
@peterebden

Description

@peterebden

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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