-
-
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
treat globals as constant within top-level expressions when possible #524
Comments
This behavior is actually expected at the moment. Since |
It's type would have to be known when it is used in the listcomp, though, as it is when I call typeof(x) directly? |
Ok, so:
Speaking of global vs function scope, i got tripped up by this one the other day:
Silly nolta, eval is for globals. |
Ah, yes. Julia's |
I tried to send the following by email but it didn't seem to work: Yes, you and I can see that the type of x doesn't change before it's used by the comprehension, but this is hard for the compiler to reason about. It doesn't yet have knowledge about which functions modify globals. We could "localize" globals inside inputs so that only assignments in the repl input itself can modify repl global variables. |
Okay, that makes sense. Perhaps we can write up some documentation on these global effects (potential) pitfalls, then? I can add that to my to-do list. (Is there a "documentation" tag?) |
Well, as I said, we could decide to make the repl effectively a "local" scope, and assume that its variables can't be modified elsewhere. |
One way to handle this would be to make each repl expression behave as though all globals where let-bound when evaluating the expression, thereby making them behave like locals while evaluating, and then copy the local value back to the global at the end. Effectively this is like saying that nothing else can change globals while the repl expression is running. Which seems reasonable. |
Wandering further down the listcomp rabbit hole:
Without some way to descope variables (MATLAB |
Leading to the type-entropy death of the universe? Grim. |
Related: #964 |
Renamed to "slow global scope" to reflect the problem, not a particular potential solution. |
At this point I think the best solution may be to solve this together with #265: track what generated code depends on the type of a global, and invalidate that code if the global's type is changed. This solves the common-case performance issue. It introduces another potential problem: if you keep changing the type of a global variables, it may cause repeated invalidation of generated code. Perhaps the assumed type of a global should be the |
Nice idea. Just following up on your mailing-list posts: I wouldn't let the global-scope problem rise to a higher priority than, say, granular package precompilation. |
That's important too but I do think this plus #265 is starting to be a priority. |
It is also possible to assume that globals are "type constant" only until a type instability is detected. If a global changes its type once, (it would seem like) it is much more likely to change again, and the slow code we currently generate seems appropriate. Static analysis might also be able to determine at compile time that a global is type unstable and avoid generating specialized code that might invalidated. |
Getting OT, but I'm with @timholy as far as priorities go, the package loading time thing is getting to be really really painful... |
We're not going to do this exact thing and #8870 covers the broader issue of global performance without presuming a particular solution. |
Stdlib: SparseArrays URL: https://github.com/JuliaSparse/SparseArrays.jl.git Stdlib branch: main Julia branch: master Old commit: cb602d7 New commit: a09f90b Julia version: 1.12.0-DEV SparseArrays version: 1.12.0 Bump invoked by: @dkarrasch Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaSparse/SparseArrays.jl@cb602d7...a09f90b ``` $ git log --oneline cb602d7..a09f90b a09f90b Adjust matvec and matmatmul! to new internal LinAlg interface (#519) 3b30333 ci: run aqua test as a standalone ci job (#537) df0a154 Add versioned Manifest files to .gitignore (#534) 4606755 Extend `copytrito!` for a sparse source (#533) 33fbc75 SparseMatrixCSC constructor with a Tuple of Integers (#523) 08d6ae1 CI: don't run `threads` tests in Windows GHA CI (attempt 2) (#530) 7408e4b Revert "Don't fail CI if codecov upload fails." (#527) 287e406 Bump julia-actions/setup-julia from 1 to 2 (#524) b5de0da Don't fail CI if codecov upload fails. (#525) 78dde4c cast to Float64 directly instead of using float (#521) a5e95ec CI: Add Apple Silicon (macOS aarch64) to the CI matrix (#505) ``` Co-authored-by: Dilum Aluthge <[email protected]>
…aLang#54406) Stdlib: SparseArrays URL: https://github.com/JuliaSparse/SparseArrays.jl.git Stdlib branch: main Julia branch: master Old commit: cb602d7 New commit: a09f90b Julia version: 1.12.0-DEV SparseArrays version: 1.12.0 Bump invoked by: @dkarrasch Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaSparse/SparseArrays.jl@cb602d7...a09f90b ``` $ git log --oneline cb602d7..a09f90b a09f90b Adjust matvec and matmatmul! to new internal LinAlg interface (JuliaLang#519) 3b30333 ci: run aqua test as a standalone ci job (JuliaLang#537) df0a154 Add versioned Manifest files to .gitignore (JuliaLang#534) 4606755 Extend `copytrito!` for a sparse source (JuliaLang#533) 33fbc75 SparseMatrixCSC constructor with a Tuple of Integers (JuliaLang#523) 08d6ae1 CI: don't run `threads` tests in Windows GHA CI (attempt 2) (JuliaLang#530) 7408e4b Revert "Don't fail CI if codecov upload fails." (JuliaLang#527) 287e406 Bump julia-actions/setup-julia from 1 to 2 (JuliaLang#524) b5de0da Don't fail CI if codecov upload fails. (JuliaLang#525) 78dde4c cast to Float64 directly instead of using float (JuliaLang#521) a5e95ec CI: Add Apple Silicon (macOS aarch64) to the CI matrix (JuliaLang#505) ``` Co-authored-by: Dilum Aluthge <[email protected]>
…aLang#54406) Stdlib: SparseArrays URL: https://github.com/JuliaSparse/SparseArrays.jl.git Stdlib branch: main Julia branch: master Old commit: cb602d7 New commit: a09f90b Julia version: 1.12.0-DEV SparseArrays version: 1.12.0 Bump invoked by: @dkarrasch Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaSparse/SparseArrays.jl@cb602d7...a09f90b ``` $ git log --oneline cb602d7..a09f90b a09f90b Adjust matvec and matmatmul! to new internal LinAlg interface (JuliaLang#519) 3b30333 ci: run aqua test as a standalone ci job (JuliaLang#537) df0a154 Add versioned Manifest files to .gitignore (JuliaLang#534) 4606755 Extend `copytrito!` for a sparse source (JuliaLang#533) 33fbc75 SparseMatrixCSC constructor with a Tuple of Integers (JuliaLang#523) 08d6ae1 CI: don't run `threads` tests in Windows GHA CI (attempt 2) (JuliaLang#530) 7408e4b Revert "Don't fail CI if codecov upload fails." (JuliaLang#527) 287e406 Bump julia-actions/setup-julia from 1 to 2 (JuliaLang#524) b5de0da Don't fail CI if codecov upload fails. (JuliaLang#525) 78dde4c cast to Float64 directly instead of using float (JuliaLang#521) a5e95ec CI: Add Apple Silicon (macOS aarch64) to the CI matrix (JuliaLang#505) ``` Co-authored-by: Dilum Aluthge <[email protected]>
So far, so good.
Wat.
(with apologies to https://www.destroyallsoftware.com/talks/wat)
The text was updated successfully, but these errors were encountered: