CloudNet icon indicating copy to clipboard operation
CloudNet copied to clipboard

feat: conditionally disable netty unsafe to leverage the ffm api

Open derklaro opened this issue 6 months ago • 1 comments

Motivation

In netty 4.2.3 a new type of ByteBuffer cleaner (or allocator) will be introduced that uses malloc and free directly using the ffm api on java 24+. In order to enable this cleaner, unsafe has to be unavailable/disabled. Since this can be a performance issue (as the ByteBuffer lifecycle might be controlled by the garbage collector if unsafe is unavailable) we only disable unsafe when the new cleaner implementation is available.

Modification

Add a "transformer" that checks if all conditions are met to disable unsafe in order to enable the ffm-based cleaner implementation. The transformer is actually only used to get a notification of the PlatformDependant0 class being loaded, it's not actually transforming anything in the class itself. The check will be disabled if the system property io.netty.noUnsafe has an explicit value set already.

Result

On netty 4.2.3+ unsafe will be disabled in favor of the ffm-linker based cleaner implementation, but only is all necessary preconditions to enable the cleaner are met.

derklaro avatar Jun 20 '25 22:06 derklaro

Test Results

 56 files  ±0   56 suites  ±0   2m 24s ⏱️ -9s 566 tests ±0  566 ✅ ±0  0 💤 ±0  0 ❌ ±0  931 runs  ±0  931 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 34886194. ± Comparison against base commit e4d1f49b.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Jun 20 '25 22:06 github-actions[bot]