Skip to content

feat: custom netty memory-segment based buffer impl#1655

Merged
derklaro merged 10 commits into
nightlyfrom
custom-memseg-buffer
Jun 18, 2025
Merged

feat: custom netty memory-segment based buffer impl#1655
derklaro merged 10 commits into
nightlyfrom
custom-memseg-buffer

Conversation

@derklaro

@derklaro derklaro commented Jun 16, 2025

Copy link
Copy Markdown
Member

Motivation

We're currently using the default memory segment backed buffer implementation provided by netty. While this implementation works, there are still some issues with it. These were resolved in upstream but never published due to the central-portal migration that wasn't done for netty5 yet.

Modification

Add a custom netty buffer implementation that is backed by memory segments with a few modifications:

  1. memory segments are allocated manually using malloc and freed using free. This means that we're not using the Arena implementations provided by the jdk (specifically the shared arena), as closing them provides a performance bottleneck due to a required thread handshake to prevent uaf. This can be quite expensive depending on the count of active threads.
  2. the bugfixes of the upstream implementation are now already present in our custom implementation. This means that the buffer should now work bug-free.
  3. the implementation contains some other cleanups that are now possible after the jdk feature became permanent, e.g. preventing segment slicing when copying segments.

Result

We're using a custom mememory-segment backed buffer implementation that doesn't contain some upstream bugs and is faster to deallocate.

@derklaro derklaro added this to the 4.0.0-RC13 milestone Jun 16, 2025
@derklaro derklaro requested a review from 0utplay June 16, 2025 18:37
@derklaro derklaro self-assigned this Jun 16, 2025
@derklaro derklaro added v: 4.X This pull should be included in the 4.0 release in: driver An issue/pull request releated to the driver module code t: improvement The pull request improves existing code labels Jun 16, 2025
@github-actions

github-actions Bot commented Jun 16, 2025

Copy link
Copy Markdown

Test Results

 52 files  +  1   52 suites  +1   2m 51s ⏱️ + 1m 30s
524 tests + 72  524 ✅ + 72  0 💤 ±0  0 ❌ ±0 
889 runs  +106  889 ✅ +106  0 💤 ±0  0 ❌ ±0 

Results for commit cdbcb80. ± Comparison against base commit 5b02c06.

This pull request removes 37 and adds 109 tests. Note that renamed tests count towards both.
eu.cloudnetservice.driver.impl.document.DocumentSerialisationTest ‑ [4] {"b":1,"s":2,"i":3,"l":4,"f":5.0,"d":6.0,"c":"/","string":"Hello, World!","bol":true,"cloud":["Ben?","Yes","No","HoHoHoHo"],"world":{"this":"is","hello":"world","insane":"!"}}, PRETTY
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [14] 2025-06-13
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [23] 08:38:20.273223011
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [28] 08:38:20.273328738Z
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [29] 08:38:20.273350489Z
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [30] 08:38:20.273372029+05:00
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [31] 08:38:20.273388129-03:00
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [34] 2025-06-13T08:38:20.273512992
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [39] 2025-06-13T08:38:20.273645801Z
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [4] 2025-06-13T08:38:20.266944953Z
…
eu.cloudnetservice.driver.impl.document.DocumentSerialisationTest ‑ [4] {"b":1,"s":2,"i":3,"l":4,"f":5.0,"d":6.0,"c":"/","string":"Hello, World!","bol":true,"cloud":["Ben?","Yes","No","HoHoHoHo"],"world":{"this":"is","insane":"!","hello":"world"}}, PRETTY
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [14] 2025-06-17
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [23] 10:16:34.297307353
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [28] 10:16:34.297998103Z
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [29] 10:16:34.298833312Z
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [30] 10:16:34.299020021+05:00
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [31] 10:16:34.299284174-03:00
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [34] 2025-06-17T10:16:34.300086492
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [39] 2025-06-17T10:16:34.300732358Z
eu.cloudnetservice.driver.impl.document.gson.JavaTimeSerializerTest ‑ [4] 2025-06-17T10:16:34.285406552Z
…

♻️ This comment has been updated with latest results.

@derklaro derklaro merged commit eba28eb into nightly Jun 18, 2025
5 checks passed
@derklaro derklaro deleted the custom-memseg-buffer branch June 18, 2025 06:43
derklaro added a commit to CloudNetService/module-rest that referenced this pull request Jun 18, 2025
This is possible again with our custom memory-segment buffers (they are
now allocated in the global arena which isn't restricted). Depends on
CloudNetService/CloudNet#1655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: driver An issue/pull request releated to the driver module code t: improvement The pull request improves existing code v: 4.X This pull should be included in the 4.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants