Skip to content

Conversation

@rafaqz
Copy link

@rafaqz rafaqz commented Jan 21, 2022

The compile time of Interact.jl (and probably other packages that use AssetRegistry) is hugely affected by JSON serialisation of the asset registry. Currently its not type stable, because JSON does not detect tuples, but mixed type vectors (the areas with the label are AssetRregistry.jl):

2022-01-21-121855_1920x1080_scrot

Using JSON 3 and specifying the type lets us use tuple:

2022-01-21-122445_1920x1080_scrot

These are the flame graphs for @profile Interact.slider(1:10). The time goes from over 15 seconds on my laptop on master, to 5-7 seconds with this PR.

@twavv
Copy link
Member

twavv commented Jan 21, 2022

🎉

Using tuples in JSON is really unidiomatic but that's a bigger change that might happen at some point in the future (along with putting the file in some other place than your home directory).

@rafaqz
Copy link
Author

rafaqz commented Jan 21, 2022

Well, it already used tuples but JSON.jl returned Vector so there were actually both. We could explicitly use Vector{Union{String,Int}} and small union optimisations would work, but that's a very unidiomatic type for julia, when JSON3.jl lets us force the Tuple perfectly well.

Copy link
Member

@twavv twavv left a comment

Choose a reason for hiding this comment

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

LGTM, can you address the couple of review comments? Happy to merge/release after.

# get existing information
prev_registry = filesize(io) > 0 ? JSON.parse(io) : Dict{String,Tuple{String, Int}}()
DT = Dict{String,Tuple{String,Int}}
prev_registry = filesize(io) > 0 ? JSON3.read(io, DT) : DT()
Copy link
Member

Choose a reason for hiding this comment

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

Can we not repeat this logic? (e.g., extract this into its own function to read the registry from disk and return it as a dict)

Copy link
Author

Choose a reason for hiding this comment

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

I refactored the code shared between register and deregister into update_registry_file

rafaqz and others added 2 commits January 23, 2022 14:02
Co-authored-by: Travis DePrato <773453+travigd@users.noreply.github.com>
@rafaqz
Copy link
Author

rafaqz commented Feb 3, 2022

Can we get this merged?

@rafaqz
Copy link
Author

rafaqz commented Feb 4, 2022

Actually this is better done with a precompile statement in JSON.jl, so closing.

@rafaqz rafaqz closed this Feb 4, 2022
@rafaqz rafaqz reopened this Feb 4, 2022
@rafaqz
Copy link
Author

rafaqz commented Feb 4, 2022

No, turns out this PR is better and I cant beat the above reduction with precompilation in JSON

@rafaqz rafaqz closed this Feb 4, 2022
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 this pull request may close these issues.

2 participants