Repository: quarkusio/quarkus
Issue: Quarkus 3.0.0.Alpha4 introduces a performance regression

### Describe the bug

A drop in mean throughput performance has been spotted while validating Camel Quarkus 3.0.0-M1 staging release upstream:
```
  2.16.0  |       30m  |  38804.35 req/s [+0.00%]  |   22357.99 req/s [+0.00%]  |                                OK  |
3.0.0-M1  |       30m  |  38857.07 req/s [+0.14%]  |   21166.75 req/s [-5.33%]  |  Potential performance regression  |
```

After investigation, it looks like the regression has been introduced when we switched to Quarkus 3.0.0.Alpha4.
From this version onward, there is a noticeable log related to direct buffers that could be a good candidate to explain the regression as shown below:
```
2023-03-29 19:32:02,511 INFO  [io.net.uti.int.PlatformDependent] (Thread-1)
Your platform does not provide complete low-level API for accessing direct buffers reliably.
Unless explicitly requested, heap buffer will always be preferred to avoid potential system instability.
```

And we see in the native-image command line that a new argument has been introduced: `-J-Dio.netty.noUnsafe=true`
This new behavior comes from commit below: https://github.com/quarkusio/quarkus/commit/ca155cae76c7caf7d6c4bbf27e9ac22305d2dbf0

I've then tested with `-Dquarkus.native.additional-build-args=-J-Dio.netty.noUnsafe=false` and the performance regression is gone. Somehow, it could mean that netty could not use unsafe and so couldn't use direct buffers.
In the end resulting in a performance penalty.

### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

The simplest way to to reproduce would be to run the Camel Quarkus performance regression tool, something like:
```
git clone git@github.com:apache/camel-quarkus.git
git checkout aa942c217a3dab5900ff175964641b798ccc62b5
mvn clean install -Dquickly
cd tooling/performance-regression
java -jar target/quarkus-app/quarkus-run.jar -an 2.16.0 3.0.0-SNAPSHOT
```

After 45 minutes run on a machine equally loaded over that period, it should print a report like:
```
                             Camel Quarkus Throughput Performance Increase Compared to Previous Version                             
 Camel Quarkus version  |  Duration  |   JVM req/s [%increase]   |  Native req/s [%increase]  |               Status               |
------------------------------------------------------------------------------------------------------------------------------------
                2.16.0  |       30m  |  38804.35 req/s [+0.00%]  |   22357.99 req/s [+0.00%]  |                                OK  |
        3.0.0-SNAPSHOT  |       30m  |  38857.07 req/s [+0.14%]  |   21166.75 req/s [-5.33%]  |  Potential performance regression  |
```

### Output of `uname -a` or `ver`

Linux me.csb 4.18.0-425.13.1.el8_7.x86_64 #1 SMP Thu Feb 2 13:01:45 EST 2023 x86_64 x86_64 x86_64 GNU/Linux

### Output of `java -version`

22.3.1.0-Final Mandrel Distribution (Java Version 17.0.6+10)

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

3.0.0.Alpha4

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

3.8.7

### Additional information

_No response_

Changed files:
extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java

diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
index 13171bec796..365f1ac191f 100644
--- a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
+++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
@@ -31,7 +31,6 @@
 import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.UnsafeAccessedFieldBuildItem;
 import io.quarkus.deployment.logging.LogCleanupFilterBuildItem;
-import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
 import io.quarkus.netty.BossEventLoopGroup;
 import io.quarkus.netty.MainEventLoopGroup;
 import io.quarkus.netty.runtime.EmptyByteBufStub;
@@ -78,7 +77,7 @@ public SystemPropertyBuildItem setNettyMachineId() {
         return new SystemPropertyBuildItem("io.netty.machineId", nettyMachineId);
     }
 
-    @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
+    @BuildStep
     NativeImageConfigBuildItem build(
             NettyBuildTimeConfig config,
             BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
@@ -95,8 +94,6 @@ NativeImageConfigBuildItem build(
         String maxOrder = calculateMaxOrder(config.allocatorMaxOrder, minMaxOrderBuildItems, false);
 
         NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder()
-                // disable unsafe usage to allow io.netty.internal.PlarformDependent0 to be reinitialized without issues
-                .addNativeImageSystemProperty("io.netty.noUnsafe", "true")
                 // Use small chunks to avoid a lot of wasted space. Default is 16mb * arenas (derived from core count)
                 // Since buffers are cached to threads, the malloc overhead is temporary anyway
                 .addNativeImageSystemProperty("io.netty.allocator.maxOrder", maxOrder)
@@ -112,14 +109,8 @@ NativeImageConfigBuildItem build(
                 .addRuntimeInitializedClass("io.netty.buffer.ByteBufUtil")
                 // The default channel id uses the process id, it should not be cached in the native image.
                 .addRuntimeInitializedClass("io.netty.channel.DefaultChannelId")
-                // Make sure to re-initialize platform dependent classes/values at runtime
-                .addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent")
-                .addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent0")
                 .addNativeImageSystemProperty("io.netty.leakDetection.level", "DISABLED");
 
-        // Also set io.netty.noUnsafe at runtime
-        systemProperties.produce(new SystemPropertyBuildItem("io.netty.noUnsafe", "true"));
-
         if (QuarkusClassLoader.isClassPresentAtRuntime("io.netty.handler.codec.http.HttpObjectEncoder")) {
             builder
                     .addRuntimeInitializedClass("io.netty.handler.codec.http.HttpObjectEncoder")
@@ -168,7 +159,8 @@ NativeImageConfigBuildItem build(
             log.debug("Not registering Netty native kqueue classes as they were not found");
         }
 
-        return builder.build();
+        return builder //TODO: make configurable
+                .build();
     }
 
     @BuildStep