Skip to content

Commit

Permalink
Increase LZS hash to 16 bits
Browse files Browse the repository at this point in the history
It really isn't a hash any more, but RAM is cheap. The hash_table is still
only 128KiB and this is userspace, not the kernel.

Bumping it to 16 bits gives about a 25% performance improvement. Dropping
the old HASH() macro and just loading the uint16_t directly yields another
3½% on top of that.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 8, 2015
1 parent 387c7ab commit 1cbf40a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lzs.c
Expand Up @@ -175,13 +175,12 @@ int lzs_compress(unsigned char *dst, int dstlen, const unsigned char *src, int s
int nr_outbits = 0;

/*
* Each pair of bytes from the input is hashed into a hash value of
* size HASH_BITS (currently 12 bits). We could use 16 bits and stop
* calling it a hash, I suppose, since RAM is cheap these days.
* This is theoretically a hash. But RAM is cheap and just loading the
* 16-bit value and using it as a hash is *much* faster.
*/
#define HASH_BITS 12
#define HASH_BITS 16
#define HASH_TABLE_SIZE (1ULL << HASH_BITS)
#define HASH(p) ((p)[0] << (HASH_BITS - 8) ^ (p)[1])
#define HASH(p) (*(uint16_t *)(p))

/*
* There are two data structures for tracking the history. The first
Expand Down

0 comments on commit 1cbf40a

Please sign in to comment.