Skip to content

Encode small hashes with a ziplist#285

Merged
antirez merged 5 commits intoredis:unstablefrom
pietern:hash-ziplist
Mar 10, 2012
Merged

Encode small hashes with a ziplist#285
antirez merged 5 commits intoredis:unstablefrom
pietern:hash-ziplist

Conversation

@pietern
Copy link
Contributor

@pietern pietern commented Jan 3, 2012

This patch switches the encoding of small hashes from zipmap to ziplist (continuation of issue #188). This is a first stab, and it may need more work: tests pass, but I haven't done performance testing (throughput, memory). Because the vanilla ziplist API is used, which doesn't provide a function to replace an element, HSET is implemented as a delete followed by a push. This causes the fields in the ziplist encoded hash to be ordered by modification time (I see this more as a by-effect than a feature).

I haven't tested the loading of a zipmap encoded hash from an older RDB yet. We may want to add an integration test for that (i.e. one that includes a prefabricated RDB with such a key).

To improve the performance of the ziplist implementation, some
functions have been converted to macros to avoid unnecessary stack
movement and duplicate variable assignments.
@pietern
Copy link
Contributor Author

pietern commented Jan 4, 2012

The following graph illustrates the performance impact of the ziplist backed hashes. All commands are executed against a hash that already contains N field/value pairs (23 + 5 bytes), and use randomized field names with a field space of N. The only command that doesn't show improvement is HGET/HMGET. The impact is caused by iterating over a slightly more complex length encoding in ziplists. Because these commands need to scan the hash N times, the impact becomes more obvious with larger N.

@pietern
Copy link
Contributor Author

pietern commented Jan 4, 2012

The memory impact for small fields/values is 9+N bytes with N being the number of pairs in the hash. The constant number is caused by the extra bytes to store length, size in bytes and a pointer to the tail element. The variable number is caused by a backlink for the value entry, which is not present in the zipmap encoding.

@antirez
Copy link
Contributor

antirez commented Jan 4, 2012

Thank you Pieter! Great work. I'll merge and add the missing integration test in the next days. This was an important part of the 2.6 release... very cool to have it now that we I'm going to call the feature freeze.

@antirez
Copy link
Contributor

antirez commented Jan 4, 2012

p.s did you generated the graphs with INFO commandstats? Thanks.

@pietern
Copy link
Contributor Author

pietern commented Jan 4, 2012

I'll push to this pull request when I get around to the integration test. The graph uses the usec_per_call field, yes. In creating it I found that it is very helpful to be able to run a piece of code (e.g. a benchmark) against N different versions, so I'll probably add that soonish as well ;-)

@pietern
Copy link
Contributor Author

pietern commented Jan 25, 2012

@antirez The integration test revealed an error in the conversion code, so it's a good thing the merge was postponed.

This patch touches a little bit of ziplist, not very invasively, but could therefore use a little more testing IMO.

@antirez antirez merged commit d3ea4c8 into redis:unstable Mar 10, 2012
antirez added a commit that referenced this pull request Jan 31, 2013
fix comments forgotten in #285 (zipmap -> ziplist)
antirez pushed a commit that referenced this pull request Feb 11, 2013
antirez pushed a commit that referenced this pull request Feb 11, 2013
Hailei pushed a commit to Hailei/redis that referenced this pull request Aug 29, 2014
Fix NPE in BuilderFactory for Double.
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Aug 29, 2016
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request May 19, 2022
Remove some dead code in object.c, ziplist is no longer used in 7.0

Some backgrounds:
zipmap - hash: replaced by ziplist in redis#285
ziplist - hash: replaced by listpack in redis#8887
ziplist - zset: replaced by listpack in redis#9366
ziplist - list: replaced by quicklist (listpack) in redis#2143 / redis#9740
oranagra pushed a commit that referenced this pull request May 22, 2022
Remove some dead code in object.c, ziplist is no longer used in 7.0

Some backgrounds:
zipmap - hash: replaced by ziplist in #285
ziplist - hash: replaced by listpack in #8887
ziplist - zset: replaced by listpack in #9366
ziplist - list: replaced by quicklist (listpack) in #2143 / #9740

Moved the location of ziplist.h in the server.c
PatKamin added a commit to PatKamin/redis that referenced this pull request Oct 28, 2022
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
Remove some dead code in object.c, ziplist is no longer used in 7.0

Some backgrounds:
zipmap - hash: replaced by ziplist in redis#285
ziplist - hash: replaced by listpack in redis#8887
ziplist - zset: replaced by listpack in redis#9366
ziplist - list: replaced by quicklist (listpack) in redis#2143 / redis#9740

Moved the location of ziplist.h in the server.c
minchopaskal pushed a commit to minchopaskal/redis that referenced this pull request Oct 16, 2025
Unified VSX and S390X code path, remove vpermxor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants