Records

C-Struct like features for Java 6+ to improve performance.

License

License

Categories

Categories

Net ORM Data
GroupId

GroupId

net.whenperformancematters
ArtifactId

ArtifactId

records
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Records
C-Struct like features for Java 6+ to improve performance.
Source Code Management

Source Code Management

https://github.com/whenperformancematters/records/tree/master/

Download records

How to add to project

<!-- https://jarcasting.com/artifacts/net.whenperformancematters/records/ -->
<dependency>
    <groupId>net.whenperformancematters</groupId>
    <artifactId>records</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.whenperformancematters/records/
implementation 'net.whenperformancematters:records:1.0.0'
// https://jarcasting.com/artifacts/net.whenperformancematters/records/
implementation ("net.whenperformancematters:records:1.0.0")
'net.whenperformancematters:records:jar:1.0.0'
<dependency org="net.whenperformancematters" name="records" rev="1.0.0">
  <artifact name="records" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.whenperformancematters', module='records', version='1.0.0')
)
libraryDependencies += "net.whenperformancematters" % "records" % "1.0.0"
[net.whenperformancematters/records "1.0.0"]

Dependencies

compile (7)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.20
com.koloboke : koloboke-api-jdk8 jar 1.0.0
com.koloboke : koloboke-impl-jdk8 jar 1.0.0
com.koloboke : koloboke-impl-common-jdk8 jar 1.0.0
net.openhft : chronicle-bytes jar 1.7.15
org.ow2.asm : asm jar 5.1
org.ow2.asm : asm-all jar 5.1

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
ch.qos.logback : logback-classic jar 1.1.7

Project Modules

There are no modules declared in this project.

Records

Latest Version

An open-source Java library to improve the memory object layout of the JVM. Relying heavily on sun.misc.Unsafe to store data off heap. It is designed for high performance applications. The new layout has features similar to C-structs, like unions and allocating consecutive memory for multiple Java objects.

At the same time Records provides a convenient API and keeps the Java OOP feeling. Depending on the application a speed up and memory reduction of factor two can be archived. In case of projects with a lot of parallel processes the scalability will see a big improvement.

Quick start

Add the following dependencies in your Maven pom.xml:

  <dependencies>
    <dependency>
      <groupId>net.whenperformancematters</groupId>
      <artifactId>records</artifactId>
      <version>1.0.0</version>
    </dependency>
  <dependencies>

Or to your Gradle build script:

dependencies {
    compile 'net.whenperformancematters:records:1.0.0'
}

Example

The best place to learn about this library is to look at the [examples] (src/test/java/net/wpm/record/samples). In generell an interface defining getter/setter methods is all it needs. Records will build the necessary classes at runtime implementing the interface and provides an API to instantiate an object of them.

Instead of a POJO class it is sufficient to just define an interface.

public interface Foo {
	public int getNumber();
	public void setNumber(int number);
	public float getFraction();
	public void setFraction(float fraction);
}

Creating an instance is done through the Records API.

public static void main(String[] args) {
		// create a record implementing the Foo interface
		Foo obj = Records.of(Foo.class);
		
		// writes the number 5 into the record
		obj.setNumber(5);
		
		// prints -> "{Number: 5, Fraction: 0.0}"
		System.out.println(obj);
}

Limitations

Right now Records has some limitations which might be crucial for other project. We nevertheless released a version 1.0.0 of it. With the knowledge about the shortcomings we still use Records in many closed source projects and think it is ready to enter the lime light.

Records can not be deleted

The current API allows the creation of single records and record sequences, but lacks the ability to delete those. It is only possible to release all the memory allocated by Records and start over again. Developer are advised to allocate the POJO like objects once at program start and reuse their memory afterwards. Not affected by this limitation are the record views, they can be created and deleted at will.

References to objects and records

A record can not hold a reference to another record or Java object. There exists a set-record method which works for records but fails upon receiving a Java object. However this method will copy the content from one record to another instead of storing a reference. While this improves the performance for later access, it is still counterintuitive to the normal Java behavior.

Questions, Comments and Ideas

We love to get in contact with the community. Feel free to e-mail us or use the issue system to suggest new features and ask questions. Pull requests are always welcome, we try to incorporate them into the master branch as fast as possible. Not sure if that typo is worth a pull request? Do it! We will appreciate it.

Versions

Version
1.0.0