Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
96abf659
Commit
96abf659
authored
Feb 03, 2015
by
antirez
Browse files
Hopefully better sort.c optimization comments.
Related to #2346.
parent
5fbb36f9
Changes
1
Show whitespace changes
Inline
Side-by-side
src/sort.c
View file @
96abf659
...
@@ -322,16 +322,16 @@ void sortCommand(redisClient *c) {
...
@@ -322,16 +322,16 @@ void sortCommand(redisClient *c) {
}
}
if
(
end
>=
vectorlen
)
end
=
vectorlen
-
1
;
if
(
end
>=
vectorlen
)
end
=
vectorlen
-
1
;
/* Optimization:
/* Whenever possible, we load elements into the output array in a more
* direct way. This is possible if:
*
*
* 1)
if t
he object to sort is a sorted set.
* 1)
T
he object to sort is a sorted set
or a list (internally sorted)
.
* 2) There is nothing to sort as dontsort is true (BY <constant string>).
* 2) There is nothing to sort as dontsort is true (BY <constant string>).
* 3) We have a LIMIT option that actually reduces the number of elements
* to fetch.
*
*
* In this case to load all the objects in the vector is a huge waste of
* In this special case, if we have a LIMIT option that actually reduces
* resources. We just allocate a vector that is big enough for the selected
* the number of elements to fetch, we also optimize to just load the
* range length, and make sure to load just this part in the vector. */
* range we are interested in and allocating a vector that is big enough
* for the selected range length. */
if
((
sortval
->
type
==
REDIS_ZSET
||
sortval
->
type
==
REDIS_LIST
)
&&
if
((
sortval
->
type
==
REDIS_ZSET
||
sortval
->
type
==
REDIS_LIST
)
&&
dontsort
&&
dontsort
&&
(
start
!=
0
||
end
!=
vectorlen
-
1
))
(
start
!=
0
||
end
!=
vectorlen
-
1
))
...
@@ -364,10 +364,7 @@ void sortCommand(redisClient *c) {
...
@@ -364,10 +364,7 @@ void sortCommand(redisClient *c) {
j
++
;
j
++
;
}
}
listTypeReleaseIterator
(
li
);
listTypeReleaseIterator
(
li
);
/* The code producing the output does not know that in the case of
/* Fix start/end: output code is not aware of this optimization. */
* sorted set, 'dontsort', and LIMIT, we are able to get just the
* range, already sorted, so we need to adjust "start" and "end"
* to make sure start is set to 0. */
end
-=
start
;
end
-=
start
;
start
=
0
;
start
=
0
;
}
}
...
@@ -427,10 +424,7 @@ void sortCommand(redisClient *c) {
...
@@ -427,10 +424,7 @@ void sortCommand(redisClient *c) {
j
++
;
j
++
;
ln
=
desc
?
ln
->
backward
:
ln
->
level
[
0
].
forward
;
ln
=
desc
?
ln
->
backward
:
ln
->
level
[
0
].
forward
;
}
}
/* The code producing the output does not know that in the case of
/* Fix start/end: output code is not aware of this optimization. */
* sorted set, 'dontsort', and LIMIT, we are able to get just the
* range, already sorted, so we need to adjust "start" and "end"
* to make sure start is set to 0. */
end
-=
start
;
end
-=
start
;
start
=
0
;
start
=
0
;
}
else
if
(
sortval
->
type
==
REDIS_ZSET
)
{
}
else
if
(
sortval
->
type
==
REDIS_ZSET
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment