-
Notifications
You must be signed in to change notification settings - Fork 9
Performance debugging: make graph.attributes a Dict
#12
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
Conversation
|
The initial latency due to type inference is pretty painful, I agree. Did you benchmark the effects of this after the initial compilation latency? I would assume that this only hurts us once, and if we add a precompile workload the initial latency will go away. In that case the tighter results in type inference should give us better runtime when accessing attributes. Unfortunately, we will always pay the precompilation latency during development but other than that it's a win to have strongly typed attributes. The "right way" to do this is probably just make the |
This should be what I've changed so far (it's a pretty tiny change), but feel free to make suggestions or commits to this branch as you see fit. I'm also open to making a change that's reconsidered later (once development is less active, or once julia doesn't have this pathological case)
Good idea. I didn't find any significant difference in runtime (though maybe I should find a bigger workload). Below are times from running all tests, including failing IR tests, via Before this change: After this change: |
src/syntax_graph.jl
Outdated
| TODO: Global attributes! | ||
| """ | ||
| struct SyntaxGraph{Attrs} | ||
| struct SyntaxGraph |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I had in mind here is too not remove the Attrs type parameter, but simply set it to Dict during construction.
This is what the existing design has in mind: we can have either a fully typed version with NamedTuple, or a flexible dynamic version with Dict.
That way we get both options within the same exact code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see; pushed a change doing this. I unfortunately couldn't achieve the same performance (from the original PR message, lower(1) is the same as before, and Pkg.test() takes about 60 seconds).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative: marking structs mutable in syntax_graph.jl, which should change some stack allocations to heap allocations. This gives me 18 seconds and 68 seconds. Updated in case you'd like to try it.
|
If the benchmarks suggest the runtime is the same, that seems like proof that that the NamedTuple is not having the desired affect here. There's one place where cloning attributes of SyntaxTree in |
|
For clarity, the long initial hang is not in type inference; it's LLVM taking forever to deal with what julia gives it (large structs on the stack are the likely culprit, thanks @gbaraldi for investigating). |
|
It's so interesting that just making these |
There's a significant delay when calling
lowerfor the first time. This PR isan attempt to improve performance without interfering too much with @c42f's
design choices.
Info
The delay is mostly JIT time, with some functions (
expand_function_def,compile_try) taking ~1.5 seconds to compile! It's become somewhat worse sincethe version of julia pre-#10, but was still present before.
Julia currently doesn't handle large immutable structs very well, and
graph.attributes(usually) being a named tuple triggers this. Since we allowit to be a Dict anyway, this change experiments with it always being a Dict.
Note that this removes our ability to freeze attributes.
Some measurements
Using julia commit
8780aa93ac84198bc7ebcbdd784f26041c99dea5and changes fromPR #10
lower(1)Before:
After:
Pkg.test()(IR tests commented out)
Before:
After: