A high-performance Java port of the mimalloc allocator, tailored for Netty.
- Mimalloc Powered: Leverages mimalloc's advanced allocation strategies (free lists, local shards).
- Tailored for Netty: Specifically designed to handle Netty's
ByteBufallocation with minimal overhead. - High Throughput: Optimized for multi-threaded network environments to ensure high and stable performance.
- Virtual-Threads Friendly: Optimized for Project Loom, preventing the memory explosion typically caused by massive
ThreadLocalusage in virtual thread scenarios.
| Requirement | Minimum Version |
|---|---|
| Java (JDK) | 1.8 or higher |
| Netty | 4.2.10.Final or newer |
Add the following dependencies to your pom.xml:
<dependencies>
<dependency>
<groupId>io.github.neoionet</groupId>
<artifactId>mimalloc</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>4.2.10.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.2.10.Final</version>
</dependency>
</dependencies>If you want to use the mimalloc allocator within your server or client transport, ensure the netty-transport dependency is included in your project as well:
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
<version>4.2.10.Final</version>
</dependency>
</dependencies>// Create an instance of the mimalloc-based allocator.
ByteBufAllocator miMallocAllocator = new MiByteBufAllocator();ByteBuf buf = miMallocAllocator.directBuffer();
buf.writeLong(123);
System.out.println(buf.readLong()); // print 123.
buf.release();ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.ALLOCATOR, miMallocAllocator) // Set the mimalloc allocator.
.childOption(ChannelOption.ALLOCATOR, miMallocAllocator) // Set the mimalloc allocator for child.
...Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.ALLOCATOR, miMallocAllocator) // Set the mimalloc allocator.
...This project would not be possible without the following open-source works:
- mimalloc - A compact general purpose allocator with excellent performance.
- Netty - An event-driven asynchronous network application framework.