Repository: netty/netty
File: microbench/src/main/java/io/netty/microbench/channel/DefaultChannelPipelineBenchmark.java (Java)

Code before:
            new SharableOutboundHandlerAdapter() {
                @Override
                public void read(ChannelHandlerContext ctx) throws Exception {
                    ctx.read();
                }

                @Override
                public void flush(ChannelHandlerContext ctx) throws Exception {
                    ctx.flush();
                }
            },
            new SharableOutboundHandlerAdapter() {
                @Override
                public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                    ctx.write(msg, promise);
                }

                @Override
                public void flush(ChannelHandlerContext ctx) throws Exception {
                    ctx.flush();
                }
            },
    };

    private static final int PIPELINE_ARRAY_LENGTH = 2048;
    private static final int PIPELINE_ARRAY_MASK = PIPELINE_ARRAY_LENGTH - 1;

    @Param({ "16" })
    public int extraHandlers;

    private ChannelPipeline[] pipelines;
    private ChannelPromise[] promises;
    private int pipelineCounter;

    @Setup(Level.Iteration)
    public void setup() {
        SplittableRandom rng = new SplittableRandom();
        pipelines = new ChannelPipeline[PIPELINE_ARRAY_LENGTH];
        promises = new ChannelPromise[PIPELINE_ARRAY_LENGTH];
        for (int i = 0; i < PIPELINE_ARRAY_LENGTH; i++) {
            EmbeddedChannel channel = new EmbeddedChannel();
            channel.config().setAutoRead(false);
            ChannelPipeline pipeline = channel.pipeline();
            pipeline.addLast(OUTBOUND_CONSUMING_HANDLER);
            for (int j = 0; j < extraHandlers; j++) {
                pipeline.addLast(HANDLERS[rng.nextInt(0, HANDLERS.length)]);
            }
            pipeline.addLast(INBOUND_CONSUMING_HANDLER);
            pipelines[i] = pipeline;
            promises[i] = pipeline.newPromise();
        }

Review comment (suggestion):
Don't worry here and make it configurable as `@Param` so you can verify how different numbers you got more easily, via `-parrayLength=<some pow of 2 value>` 

Code after:
            new SharableOutboundHandlerAdapter() {
                @Override
                public void read(ChannelHandlerContext ctx) throws Exception {
                    ctx.read();
                }

                @Override
                public void flush(ChannelHandlerContext ctx) throws Exception {
                    ctx.flush();
                }
            },
            new SharableOutboundHandlerAdapter() {
                @Override
                public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                    ctx.write(msg, promise);
                }

                @Override
                public void flush(ChannelHandlerContext ctx) throws Exception {
                    ctx.flush();
                }
            },
    };

    @Param({ "1024" })
    private int pipelineArrayLength;
    private int pipelineArrayMask;

    @Param({ "16" })
    public int extraHandlers;

    private ChannelPipeline[] pipelines;
    private ChannelPromise[] promises;
    private int pipelineCounter;

    @Setup(Level.Iteration)
    public void setup() {
        SplittableRandom rng = new SplittableRandom();
        pipelineArrayMask = pipelineArrayLength - 1;
        pipelines = new ChannelPipeline[pipelineArrayLength];
        promises = new ChannelPromise[pipelineArrayLength];
        for (int i = 0; i < pipelineArrayLength; i++) {
            EmbeddedChannel channel = new EmbeddedChannel();
            channel.config().setAutoRead(false);
            ChannelPipeline pipeline = channel.pipeline();
            pipeline.addLast(OUTBOUND_CONSUMING_HANDLER);
            for (int j = 0; j < extraHandlers; j++) {
                pipeline.addLast(HANDLERS[rng.nextInt(0, HANDLERS.length)]);
            }
            pipeline.addLast(INBOUND_CONSUMING_HANDLER);
            pipelines[i] = pipeline;