Comments (6)
I believe that any
!
function is assumed to be non-allocating, and that this goes against this.
It's a style convention, not something enforced, and it's about modifying at least one of arguments, not being entirely non-allocating.
from julia.
I am programming non-allocating algorithms for simulations
Why must your algorithms not allocate? If it is for performance reasons, remember that unexpected allocations are typically a sign of type instability or other major performance issues, but allocations themselves are not all that slow and can enable faster algorithms.
What are the slower non-allocating
algorithms
?
On Julia 1.9+, you can use alg=QuickSort
. On older versions there are none (QuickSort
sometimes does allocate)
julia> VERSION
v"1.8.5"
julia> x = rand(1:10, 100);
julia> @b sort!($x, alg=QuickSort)
248.288 ns (1 allocs: 144 bytes)
I just make a fork of official doc, put some text in and then we take it from there?
Yes! Once you are ready to contribute the changes you've made to the official docs, make a pull request, and feel free to @ me in it.
from julia.
I believe that any
!
function is assumed to be non-allocating, and that this goes against this.It's a style convention, not something enforced, and it's about modifying at least one of arguments, not being entirely non-allocating.
I don't disagree that !
can be simply taking as modify arguments in place
but I believe that most instinctively see it as does not allocate
. Even if one does not agree with this, I still think it would be beneficial to somewhere in sort
functions, to actually mention the scratchspace
variable.
from julia.
Scratchspace handling in sorting is okay but not perfect. For example, sometimes it still allocates when passed a scratchspace. I don't want to commit to keeping the current system as is forever. For example, it's possible using Memory might be better. Consequently, I chose not to publicize it (and therefore make it a part of the stable API) when I added it.
I have yet to find a single real-world example where explicitly passing a scratch space to sort!
or any of its variants is a good idea or even has a measurable impact on performance. Until someone finds such an example, or scratch space handling is perfect, I'm inclined to think it's premature to publicize & document it.
Actionable things here
- Document that sorting may allocate even when the function ends with an
!
, and note that slower non-allocatingalg
s exist. - Document more clearly that
!
does not mean non-allocating.
from julia.
I have yet to find a single real-world example where explicitly passing a scratch space to sort! or any of its variants is a good idea or even has a measurable impact on performance. Until someone finds such an example, or scratch space handling is perfect, I'm inclined to think it's premature to publicize & document it.
FWIW, I have experimented with scratch spaces for sort! in my code (repetitive sorting of rows and columns of huge sparse matrices), which gave 1-3% overall speed up in linear algebra for particular "real-world" examples.
So I think it is a nice improvement :), though no idea how useful it is in general
from julia.
Scratchspace handling in sorting is okay but not perfect. For example, sometimes it still allocates when passed a scratchspace. I don't want to commit to keeping the current system as is forever. For example, it's possible using Memory might be better. Consequently, I chose not to publicize it (and therefore make it a part of the stable API) when I added it.
I have yet to find a single real-world example where explicitly passing a scratch space to
sort!
or any of its variants is a good idea or even has a measurable impact on performance. Until someone finds such an example, or scratch space handling is perfect, I'm inclined to think it's premature to publicize & document it.Actionable things here
- Document that sorting may allocate even when the function ends with an
!
, and note that slower non-allocatingalg
s exist.- Document more clearly that
!
does not mean non-allocating.
Thanks for detailed explanation.
Okay, if scratchspace is not part of official/stable API, it does not make sense to document it inside of ?
in my opinion - especially if providing a scratch space at times is not enough to avoid allocations. What are the slower non-allocating algorithms
?
I think what you suggest by improving the explanation here, https://docs.julialang.org/en/v1/manual/style-guide/#bang-convention, to highlight that in-place operations does not mean non-allocating. I just make a fork of official doc, put some text in and then we take it from there?
I had a weird edge case, in which if I commented out a line, then sortperm! would not allocate at all, if I commented it in, it would allocate once. I am programming non-allocating algorithms for simulations, so I need to ensure there is truly none - this is why I spotted it in the first place.
Kind regards
from julia.
Related Issues (20)
- BUG: `^(::Float64, ::Union{Int, Float64})` incorrect for very large negative exponents HOT 10
- REPL: path completion hints shouldn't expand `~` to user dir
- Loading test "relocatable upgrades" fails locally HOT 3
- generic method for `top_set_bit` gives wrong result HOT 3
- at-atomic fields with at-kwdef and field defaults doesn't work HOT 1
- Implementation of `(first|last)(::OrdinalRange)` is not generic
- ASAN throwing heap-buffer-overflow errors during precompilation HOT 4
- Disallow size zero memory HOT 6
- Displaying array with unsigned indices throws HOT 1
- Integer overflow in `skip(s::IOBuffer, typemax(Int64))` can cause seg fault HOT 2
- Expose codegen option to emit dwarf debug info for native code HOT 3
- Wrong line number in error for duplicate static parameter on a constructor
- Add way to create a custom threadpool HOT 1
- On "llvmcall with integer pointers is deprecated, use an actual pointer type instead." on nightly HOT 3
- BUG: Unnecessary allocations when including `<:` for abstract type in `Union` for a keyword argument HOT 1
- `@threads` macro cause wrong line numbers in stacktrace
- `filter!` corrupts `SparseVector` HOT 10
- Document of `OrdinalRange` doesn't cover `Rational`
- Wrong typed `nothing` mixed in phi nodes HOT 2
- Consistently treat `_` as unused in function argument lists
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.