-
-
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
variable numbers of keyword arguments as dict #4916
Comments
I'd recommend doing some performance experiments. I suspect a dict wouldn't be a win until the number of keyword arguments was pretty large (probably > 20), which doesn't happen very often. |
One option might be to make a new dictionary type for small dictionaries On Sunday, November 24, 2013, Jeff Bezanson wrote:
|
I'll try to do some tests soon. I like @kmsquire's idea, at least then use code isn't cluttered with blocks of |
Don't know if @WestleyArgentum had time to dig into this issue, but I think it would be a good idea to have varargs keyword arguments as a Dict (like in Python for example). From usability point of view I think it would be a win (I find it more natural). If there is a performance cost, as @kmsquire said, maybe we could try to implement a Dict type efficient for small amount of values inside ? Edit: I compare access time to Vector{(Symbol, ASCIIString)} and Dict{Symbol, ASCIIString} with various number of elements (1 -> 100). For each test case, I look 100k for every element in the collection. On my machine:
It seems that Array are faster until number of elements reach 14 (I agree that it is a lot of keyword arguments...). And then Dict becomes faster. But while Array is faster for few elements, the difference seems quite reduced. For 100k x (access to each element of the collection), the difference is always x millisecs. Tell me if I'm wrong about the bench, but from a performance point of view, the advantage of Array over Dict seems negligible. |
Note that the issue of having a specialized |
I think such a situation could be handled in a uniform way with a function that goes over pairs:
|
@ntessore, except that this is a terrible way to look up something in a The point is that there are potentially several places where a specialized |
Of course it does not make any sense for a Dict, but that was the first container holding pairs I could think of. My point was that it is generally useful to extract something from a set of (key, value) pairs, so maybe there is room for a generic function (that one can then specialise as necessary, e.g. for dictionaries). |
(In Scheme, the |
Why not adding a method get to array of pairs?
|
@remusao, because arrays already have a |
I sometimes want to print out the args in the same order so I wouldn't want to have this turned into an unordered dict. I would much rather have a new datatype that was optimized for a list of pairs that was really fast for <5 pairs. |
Varargs keywords will either be immutable dicts or named tuples, so this will be fixed in 1.0 one way or another. |
Whatever you do, please preserve the argument order (so either a tuple or an ordered dictionary would keep me happy). |
Would be great to have an update on if this is happening by feature freeze. A PR exists in #21915, but that is not marked 1.0. |
I'll update that PR to use named tuples. |
Doesn't that mean that every time you use a function with a different ordering of keyword arguments it will have to create a new specialization of Tupple? Is there any way around this? |
Basically yes, but that won't necessarily be a problem in practice. We'll find out. |
Inside of a function with this signature,
args
will be an array of tuples containing symbols and values. Cool, but the array will be unordered, so I pretty much have to loop over it trying to match symbols.I think it would be really cool if
args
came in as a dictionary. I'm guessing there would be some overhead involved in that, and that's perhaps why it has not been done. But I wonder if the overhead involved in looping over symbols and doing a bunch of string comparisons (I think that's what's happening, could be wrong) might even outweigh the dict creation.I didn't see an issue, but has this been considered?
The text was updated successfully, but these errors were encountered: