-
Notifications
You must be signed in to change notification settings - Fork 1.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
Sorted set new commands: ZDIFF, ZDIFFSTORE, ZINTER, ZINTERCARD, and ZUNION #2075
Sorted set new commands: ZDIFF, ZDIFFSTORE, ZINTER, ZINTERCARD, and ZUNION #2075
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here! Added some comments inline - as always happy to adjust and push or just keep commenting, whichever is a bigger time/sync save on your end. A few questions inline for thoughts!
@slorello89 I've touched this a lot, so would appreciate a third set of eyes if you get a chance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NickCraver just have some questions about the efficiency vs maintainability bits of the Message Creation.
|
||
private Message GetSortedSetCombineCommandMessage(SetOperation operation, RedisKey[] keys, double[]? weights, Aggregate aggregate, bool withScores, CommandFlags flags) | ||
{ | ||
var command = operation switch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to move this logic to the SetOperation
enum as an extension method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 This makes sense with an arg - done!
} | ||
|
||
var i = 0; | ||
var values = new RedisValue[1 + keys.Length + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much more expensive would it be to initialize a List with this capacity and using Add
/AddRange
as opposed to an array and then having to track i
, this is a bit. . . feels like we're reinventing the wheel here? List<T>(int)
is effectively just doing the same initialization, since it's initialized with the correct capacity it shouldn't over allocate nor have to dynamically reallocate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's allocate more than double. At the very lease we're resizing without sizes, but also: look inside Message
to see a .ToArray()
which is going to copy as well. I agree it's not awesome to do things manually, but 2x+ allocations aren't awesome either :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I gotcha. TIL
if (keys == null) throw new ArgumentNullException(nameof(keys)); | ||
|
||
var i = 0; | ||
var values = new RedisValue[1 + keys.Length + (limit > 0 ? 2 : 0)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
@slorello89 made some tweaks (good suggestions!) - done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Covers:
ZDIFF
ZDIFFSTORE
ZINTER
ZINTERCARD
ZUNION
#2055