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

Fix DEFAULT_PARSERCONTEXT, speed up parsing. #359

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ function unparameterize_type(T::Type)
end

# Workaround for slow dynamic dispatch for creating objects
const DEFAULT_PARSERCONTEXT = ParserContext{Dict{String, Any}, Int64, false, nothing}()
const DEFAULT_PARSERCONTEXT = ParserContext{Dict{String, Any}, Int64, true, nothing}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change the default to be a non-strict spec, we will certainty want to update the docs and make a version bump. The Python docs may serve as a guide for communicating this: #280 (comment)

Copy link
Author

@Zentrik Zentrik Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something, this is a default in the sense that there is a fast path for it. This change doesn't change the result but is merely a performance improvement. If you look further down you'll see that these are the default parameters for parse.

function _get_parsercontext(dicttype, inttype, allownan, null)
if dicttype == Dict{String, Any} && inttype == Int64 && !allownan
if dicttype == Dict{String, Any} && inttype == Int64 && allownan && null === nothing
DEFAULT_PARSERCONTEXT
else
ParserContext{unparameterize_type(dicttype), inttype, allownan, null}.instance
Expand Down
Loading