-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
EA: use embedded CodeInstance
directly for escape cache lookup
#56860
Conversation
ba68271
to
9f60a99
Compare
Compiler/test/EAUtils.jl
Outdated
- `token_symbol::Symbol = gensym(:EA)`: | ||
specifies the cache token symbol to use, by default a new symbol is generated to ensure |
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.
gensym
is somewhat expensive for this (since it is permanently allocated), and only ensures weak local uniqueness (it repeats values commonly). Is this the only way we have of being able to disable the cache?
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 think you just want mutable struct EscapeAnalyzerCacheToken; end
here, so you are allocating a real unique token each time, though it is a bit of a mistake to put anonymous tokens in the global cache (it can make the runtime much slower)
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.
Yes, allocating a mutable struct
might be a better approach. Since EAUtils.jl is primarily used for debugging and testing purposes, the impact on runtime performance from indiscriminately creating code caches should be limited.
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.
Apologies, it seems your concern was indeed valid. @benchmark code_escapes(...)
is used frequently, and in such cases, it could lead to undesirable situations. #56868
`Expr(:invoke)` now directly embeds `CodeInstance`, so `EscapeAnalysis` should also directly look it up when utilizing the cache. Similarly, the cache lookup mechanism in `EscapeAnalyzer` within EAUtils.jl has been updated. This update revealed a logic error in the previous `EscapeAnalyzer` implementation, resulting in one test being marked as `@test_broken`. A new test case addressing this logic error has also been added.
9f60a99
to
1a28077
Compare
In #56860, `EAUtils.EscapeAnalyzer` was updated to create a new cache for each invocation of `code_escapes`, similar to how Cthulhu.jl behaves. However, `code_escapes` is often used for performance analysis like `@benchmark code_escapes(...)`, and in such cases, a large number of `CodeInstance`s can be generated for each invocation. This could potentially impact native code execution. So this commit changes the default behavior so that `code_escapes` uses the same pre-existing cache by default. We can still opt-in to perform a fresh analysis by specifying `cache_token=EAUtils.EscapeAnalyzerCacheToken()`.
In #56860, `EAUtils.EscapeAnalyzer` was updated to create a new cache for each invocation of `code_escapes`, similar to how Cthulhu.jl behaves. However, `code_escapes` is often used for performance analysis like `@benchmark code_escapes(...)`, and in such cases, a large number of `CodeInstance`s can be generated for each invocation. This could potentially impact native code execution. So this commit changes the default behavior so that `code_escapes` uses the same pre-existing cache by default. We can still opt-in to perform a fresh analysis by specifying `cache_token=EAUtils.EscapeAnalyzerCacheToken()`.
In #56860, `EAUtils.EscapeAnalyzer` was updated to create a new cache for each invocation of `code_escapes`, similar to how Cthulhu.jl behaves. However, `code_escapes` is often used for performance analysis like `@benchmark code_escapes(...)`, and in such cases, a large number of `CodeInstance`s can be generated for each invocation. This could potentially impact native code execution. So this commit changes the default behavior so that `code_escapes` uses the same pre-existing cache by default. We can still opt-in to perform a fresh analysis by specifying `cache_token=EAUtils.EscapeAnalyzerCacheToken()`.
Expr(:invoke)
now directly embedsCodeInstance
, soEscapeAnalysis
should also directly look it up when utilizing the cache. Similarly, the cache lookup mechanism inEscapeAnalyzer
within EAUtils.jl has been updated. This update revealed a logic error in the previousEscapeAnalyzer
implementation, resulting in one test being marked as@test_broken
. A new test case addressing this logic error has also been added.