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

errdefer in json.parseInternal causes lots of code generation #5327

Closed
leroycep opened this issue May 12, 2020 · 3 comments
Closed

errdefer in json.parseInternal causes lots of code generation #5327

leroycep opened this issue May 12, 2020 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@leroycep
Copy link
Contributor

Specifically, this errdefer here:

zig/lib/std/json.zig

Lines 1443 to 1449 in f2d3266

errdefer {
inline for (structInfo.fields) |field, i| {
if (fields_seen[i]) {
parseFree(field.field_type, @field(r, field.name), options);
}
}
}

            errdefer {
                inline for (structInfo.fields) |field, i| {
                    if (fields_seen[i]) {
                        parseFree(field.field_type, @field(r, field.name), options);
                    }
                }
            }

Later, there is an inline loop for checking if the JSON key matches any of the fields. Inside that inline loop it calls try parse(...).

When I add some @compileLog statements inside the errdefer's inline loop and try to parse this glTF struct, it logs over 5000 calls to the @compileLog statement.

Fixes

  • Remove the errdefer and manually catch the error
  • Make errdefer smart enough to avoid generating this code O(n^2) times
    • The code to catch the error only need to be generated once in this case. Not sure if this is true all cases like this.
@LemonBoy
Copy link
Contributor

This is #283.

@yurapyon
Copy link
Contributor

yurapyon commented Aug 22, 2020

Slightly off topic, but I was getting some issues trying to use json.parse on a recursive data structure.
The compiler was saying it couldn't infer the type of the error returned from json.parse.
I was gonna try adding the error type explicitly myself to make sure that fixes it but. yeah 👍

@andrewrk
Copy link
Member

andrewrk commented Oct 4, 2020

This is #283.

☝️

This will be solved in stage2 only.

@andrewrk andrewrk closed this as completed Oct 4, 2020
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend. labels Oct 4, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

4 participants