• Stars
    star
    762
  • Rank 59,625 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zero-allocation hashing for Java

Zero-Allocation Hashing

Chronicle Software

badge javadoc GitHub release%20notes subscribe brightgreen measure?project=OpenHFT Zero Allocation Hashing&metric=alert status

About

This project provides a Java API for hashing any sequence of bytes in Java, including all kinds of primitive arrays, buffers, CharSequence and more.

Written for Java 7+ under Apache 2.0 license.

The key difference compared to other similar projects, e.g. Guava hashing, is that this has no object allocation during the hash computation and does not use ThreadLocal.

The implementation utilises native access where possible, but is also platform-endianness-agnostic. This provides consistent results whatever the byte order, while only moderately affecting performance.

Currently long-valued hash function interface is defined for 64-bit hash, and long[]-valued hash function interface for more than 64-bit hash, with the following implementations (in alphabetical order):

  • CityHash, version 1.1 (latest; 1.1.1 is a C++ language-specific maintenance release).

  • Two algorithms from FarmHash: farmhashna (introduced in FarmHash 1.0) and farmhashuo (introduced in FarmHash 1.1).

  • MetroHash (using the metrohash64_2 initialization vector).

  • MurmurHash3 128-bit and low 64-bit.

  • wyHash, version 3.

  • xxHash.

  • xxh3, xxh128, 128-bit and 64 bit.

These are thoroughly tested with LTS JDKs 7, 8, and 11, the latest non-LTS JDKs 16 on both little- and big- endian platforms. Other non-LTS JDKs from 9 should also work, but they will not be tested from half year after EOL.

Performance

Tested on Intel Core i7-4870HQ CPU @ 2.50GHz

Algorithm Speed, GB/s Bootstrap, ns

xxHash

9.5

6

FarmHash na

9.0

6

FarmHash uo

7.2

7

CityHash

7.0

7

MurmurHash

5.3

12

MetroHash

??

??

WyHash

??

??

To sum up,

When to use Zero-Allocation Hashing

  • You need to hash plain byte sequences, memory blocks or "flat" objects.

  • You want zero-allocation and good performance (at Java scale).

  • You need hashing to be agile with regards to byte ordering.

When not to use Zero-Allocation Hashing

  • You need to hash POJOs whose actual data is scattered in memory between managed objects. There is no simple way to hash these using this project, for example, classes such as:

        class Person {
            String givenName, surName;
            int salary;
        }
  • You need to hash byte sequences of unknown length, for the simpliest example, Iterator<Byte>.

  • You need to transform the byte sequence (e.g. encode or decode it with a specific coding), and hash the resulting byte sequence on the way without dumping it to memory.

Quick start

Gradle:

dependencies {
    implementation 'net.openhft:zero-allocation-hashing:0.16'
}

Or Maven:

<dependency>
  <groupId>net.openhft</groupId>
  <artifactId>zero-allocation-hashing</artifactId>
  <version>0.16</version>
</dependency>

In Java:

long hash = LongHashFunction.wy_3().hashChars("hello");

See JavaDocs for more information.

Contributions are most welcome!

See the list of open issues.

More Repositories

1

Chronicle-Queue

Micro second messaging that stores everything to disk
Java
3,130
star
2

Chronicle-Map

Replicate your Key Value Store across your network, with consistency, persistance and performance.
Java
2,669
star
3

Java-Thread-Affinity

Bind a java thread to a given core
Java
1,724
star
4

Java-Runtime-Compiler

Java Runtime Compiler
Java
617
star
5

OpenHFT

Parent module to include active modules
Shell
609
star
6

Chronicle-Core

Low level access to native memory, JVM and OS.
Java
528
star
7

Chronicle-Wire

A Low Garbage Java Serialisation Library that supports multiple formats
Java
464
star
8

Chronicle-Bytes

Chronicle Bytes has a similar purpose to Java NIO's ByteBuffer with many extensions
Java
382
star
9

Chronicle-Engine

A high performance, low latency, reactive processing framework
338
star
10

Java-Lang

Java Language support
Java
286
star
11

Chronicle-Network

A High Performance Network ( TCP/IP ) Library
Java
243
star
12

Chronicle-Logger

A sub microsecond java logger, supporting standard logging APIs such as Slf & Log4J
Java
220
star
13

Chronicle-Threads

Java
167
star
14

Chronicle-Values

Java
102
star
15

Chronicle-Algorithms

Java
77
star
16

JLBH

JLBH
Java
68
star
17

Chronicle-Queue-Demo

Sample programs for Chronicle Queue
Java
65
star
18

Chronicle-Accelerate

HFT meets Blockchain in Java platform
Java
59
star
19

Chronicle-TimeSeries

Multi-Threaded Time Series library
Java
59
star
20

Chronicle-Decentred

Framework for building Secure Scalable Microservices on Distributed Ledger Technology
Java
50
star
21

Chronicle-Salt

Chronicle wrapper for the NaCl library
Java
30
star
22

Chronicle-Test-Framework

Java
24
star
23

Chronicle-Ticker

A time ticker as a light weight clock
Java
23
star
24

RFC

RFC's used by OpenHFT
21
star
25

Chronicle-Websocket-Jetty

Provide Websocket access via Jetty
Java
17
star
26

Puzzles

OpenHFT Puzzles
Java
15
star
27

jvm-micro-benchmarks

Microbenchmarks for JVM code.
Java
14
star
28

Spoon

Java
11
star
29

Chronicle-Engine-GUI

CSS
11
star
30

Exception-Handler

Open a browser with a message about an Exception.
Java
10
star
31

Stage-Compiler

Java
8
star
32

Binary-Compatibility-Enforcer-Plugin

Wraps the Java API ComplianceChecker into a maven plugin
Java
7
star
33

Chronicle-Common

Java
6
star
34

Chronicle-Coder

Encode and decode data as symbols and readable words
Java
5
star
35

Posix

Java
5
star
36

Microservice-Benchmark

Open Microservices Benchmark
Java
5
star
37

Chronicle-Analytics

Support for Analytics
Java
4
star