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

EA: use embedded CodeInstance directly for escape cache lookup #56860

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

aviatesk
Copy link
Member

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.

@aviatesk aviatesk force-pushed the avi/EAUtils-cache branch 2 times, most recently from ba68271 to 9f60a99 Compare December 18, 2024 18:17
Comment on lines 346 to 347
- `token_symbol::Symbol = gensym(:EA)`:
specifies the cache token symbol to use, by default a new symbol is generated to ensure
Copy link
Member

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?

Copy link
Member

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)

Copy link
Member Author

@aviatesk aviatesk Dec 18, 2024

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.

Copy link
Member Author

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.
@aviatesk aviatesk merged commit 5d72906 into master Dec 19, 2024
5 of 7 checks passed
@aviatesk aviatesk deleted the avi/EAUtils-cache branch December 19, 2024 03:51
aviatesk added a commit that referenced this pull request Dec 19, 2024
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()`.
aviatesk added a commit that referenced this pull request Dec 19, 2024
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()`.
aviatesk added a commit that referenced this pull request Dec 20, 2024
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()`.
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