-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add fast path for very small Dicts? #10907
Comments
The code used by As regards |
Have you defined a |
@nalimilan For a code example clone Equations.jl and:
@toivoh |
Does hash(p::Pow) = hash(p.x) + hash(p.y) work? |
Yep, thank you. |
@jhlq You could check a subset manually, but I don't think that's a reasonable thing to do in the standard library function. For a particular application, you may be able to know in advance what the typical number of unique values will be. Regarding |
Yeah previously there has been a lot of duplicates due to using permutations to match everything, have implemented expression sorting now so the location of numbers symbols and components are known which will make it possible to phase out permutations. Will make a branch with immutables and see how that works out. |
Maybe Dicts would benefit from a fast path that uses linear search for < 10 elements or so. |
Maybe Sets would benefit from not using Dicts?
Or are those 80 bytes already cared for? |
There is only one julia> f() = @time a = nothing;
julia> f()
elapsed time: 7.68e-7 seconds (0 bytes allocated) |
Ah, good. Still seems funny though that sets carry around a bunch of arrows connected to their contents all pointing at a location to signify that they don't point anywhere. |
I don't think we do that, either: julia> sizeof(Array(Void, 1000000))
0 |
Yes, |
We most definately do.
There it is, right between the x and the nothing. It may be a weightless arrow but it is not invisible and artistically isn't less redundancy more beautiful? |
I agree that less redundancy is more beautiful, which is why Sets reuse Dicts instead of re-implementing the same functionality. |
How about if Dicts are split into layers of arrowless keys, arrowadders and values? |
Would #8674 apply? |
I think it would be an interesting experiment to implement a general set-of-tuples data structure, sorted and/or indexed, queryable in various ways, and see if it can be as fast as Set and Dict. I bet it's possible. |
Such an incitement to dig into the source code cannot go unheeded, the todolist has been expanded |
I've just published (it is not in METADATA yet) https://github.com/blackrock/NamedTuples.jl This uses immutable types in place of small immutable dicts. This was written for a different purpose, but might help in this case. If you only use field accessors on the NamedTuples the performance is the same as regular field access. |
@mdcfrancis That looks great! |
My use case would be to use this data structure as key in a dictionary. Also, the fields are not symbols but double-ended queues, so there is no natural ordering to them. |
Was at first surprised that unique doesn't filter custom types even if they evaluate to equal by == but the helpdoc does say they should be equivalent and \equiv evaluates to
is
, however have noticed several times on both 0.3 and 0.4 that functions filling up an array with objects created through permutations and thenreturn unique(result)
will produce an array of variable length from a deterministic algorithm. The most recent encounter was withfindpows
(in this commit) before unique was replaced with uniquefilter. Have not had the handpower to unwrap a case into a neat isolated example and would not have opened this if not for the following unearthed feature ofuniquefilter{T}(a::Array{T})=pushallunique!(T[],a)
:The text was updated successfully, but these errors were encountered: