Skip to content

refactor(fd/socket/udp): Flatten deeply nested if chains by reordering - #2508

Merged
mkroening merged 1 commit into
hermit-os:mainfrom
fogti:net-socket-udp-refactor
Aug 23, 2026
Merged

refactor(fd/socket/udp): Flatten deeply nested if chains by reordering#2508
mkroening merged 1 commit into
hermit-os:mainfrom
fogti:net-socket-udp-refactor

Conversation

@fogti

@fogti fogti commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

I found this code segment very hard to reach, so I switched the if and else parts including conditions around in a few places.

I haven't measured the performance impact yet.

@fogti
fogti force-pushed the net-socket-udp-refactor branch from 4d36c0e to 118438f Compare June 25, 2026 13:31

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Results

Details
Benchmark Current: 1cccf6c Previous: 2e23902 Performance Ratio
startup_benchmark Build Time 95.10 s 80.34 s 1.18
startup_benchmark File Size 0.75 MB 0.80 MB 0.94
Startup Time - 1 core 0.74 s (±0.02 s) 0.75 s (±0.02 s) 0.99
Startup Time - 2 cores 0.75 s (±0.01 s) 0.74 s (±0.02 s) 1.02
Startup Time - 4 cores 0.76 s (±0.02 s) 0.74 s (±0.02 s) 1.02
multithreaded_benchmark Build Time 95.24 s 82.11 s 1.16
multithreaded_benchmark File Size 0.88 MB 0.86 MB 1.03
Multithreaded Pi Efficiency - 2 Threads 66.40 % (±6.09 %) 85.89 % (±6.61 %) 0.77
Multithreaded Pi Efficiency - 4 Threads 40.75 % (±3.21 %) 43.43 % (±2.56 %) 0.94
Multithreaded Pi Efficiency - 8 Threads 20.01 % (±1.89 %) 25.76 % (±1.53 %) 0.78
micro_benchmarks Build Time 215.82 s 80.40 s 2.68
micro_benchmarks File Size 0.89 MB 0.86 MB 1.03
Scheduling time - 1 thread 180.97 ticks (±40.78 ticks) 62.65 ticks (±4.06 ticks) 2.89
Scheduling time - 2 threads 104.77 ticks (±23.38 ticks) 34.08 ticks (±4.10 ticks) 3.07
Micro - Time for syscall (getpid) 9.38 ticks (±5.65 ticks) 3.45 ticks (±0.58 ticks) 2.72
Memcpy speed - (built_in) block size 4096 57485.43 MByte/s (±40365.65 MByte/s) 82448.38 MByte/s (±56997.13 MByte/s) 0.70
Memcpy speed - (built_in) block size 1048576 13690.45 MByte/s (±11085.20 MByte/s) 30585.98 MByte/s (±24707.84 MByte/s) 0.45
Memcpy speed - (built_in) block size 16777216 11773.95 MByte/s (±9826.59 MByte/s) 26340.06 MByte/s (±21720.96 MByte/s) 0.45
Memset speed - (built_in) block size 4096 57504.49 MByte/s (±40378.34 MByte/s) 82292.76 MByte/s (±56891.50 MByte/s) 0.70
Memset speed - (built_in) block size 1048576 14015.97 MByte/s (±11271.80 MByte/s) 31323.85 MByte/s (±25145.86 MByte/s) 0.45
Memset speed - (built_in) block size 16777216 12073.63 MByte/s (±9991.43 MByte/s) 27104.68 MByte/s (±22209.94 MByte/s) 0.45
Memcpy speed - (rust) block size 4096 52342.83 MByte/s (±37822.26 MByte/s) 74097.96 MByte/s (±51811.44 MByte/s) 0.71
Memcpy speed - (rust) block size 1048576 13998.10 MByte/s (±12058.52 MByte/s) 30361.60 MByte/s (±24602.37 MByte/s) 0.46
Memcpy speed - (rust) block size 16777216 11722.06 MByte/s (±9755.45 MByte/s) 27625.34 MByte/s (±22806.88 MByte/s) 0.42
Memset speed - (rust) block size 4096 52709.68 MByte/s (±38072.86 MByte/s) 74373.47 MByte/s (±51976.48 MByte/s) 0.71
Memset speed - (rust) block size 1048576 14365.20 MByte/s (±12278.23 MByte/s) 31110.89 MByte/s (±25033.24 MByte/s) 0.46
Memset speed - (rust) block size 16777216 11983.43 MByte/s (±9890.80 MByte/s) 28386.93 MByte/s (±23265.03 MByte/s) 0.42
alloc_benchmarks Build Time 212.32 s 74.76 s 2.84
alloc_benchmarks File Size 0.82 MB 0.87 MB 0.94
Allocations - Allocation success 91.38 % 91.31 % 1.00
Allocations - Deallocation success 100.00 % 100.00 % 1
Allocations - Pre-fail Allocations 61.60 % 61.44 % 1.00
Allocations - Average Allocation time 24512.81 Ticks (±1527.92 Ticks) 5860.58 Ticks (±98.43 Ticks) 4.18
Allocations - Average Allocation time (no fail) 25825.27 Ticks (±1848.23 Ticks) 6554.81 Ticks (±92.86 Ticks) 3.94
Allocations - Average Deallocation time 8284.34 Ticks (±1778.33 Ticks) 1805.01 Ticks (±250.35 Ticks) 4.59
mutex_benchmark Build Time 218.25 s 79.82 s 2.73
mutex_benchmark File Size 0.89 MB 0.86 MB 1.03
Mutex Stress Test Average Time per Iteration - 1 Threads 36.18 ns (±8.04 ns) 12.10 ns (±0.41 ns) 2.99
Mutex Stress Test Average Time per Iteration - 2 Threads 33.46 ns (±10.37 ns) 40.26 ns (±1.68 ns) 0.83

This comment was automatically generated by workflow using github-action-benchmark.

@mkroening mkroening self-assigned this Aug 23, 2026
@mkroening

mkroening commented Aug 23, 2026

Copy link
Copy Markdown
Member

Good idea. 👍 Do you still want to pursue this? :)

@fogti

fogti commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Yes. Do we have any benchmarks one could mod for this? afaik the existing benchmarks (e.g. in uhyve) only use TCP…

@mkroening

Copy link
Copy Markdown
Member

This is only a trivial refactor, right? I don't expect any performance changes here. Or am I missing any changes that you expect to be difficult to optimize?

@fogti
fogti force-pushed the net-socket-udp-refactor branch from 118438f to 1cccf6c Compare August 23, 2026 14:32
@github-actions github-actions Bot added the fd label Aug 23, 2026
@fogti
fogti marked this pull request as ready for review August 23, 2026 14:34
@mkroening
mkroening force-pushed the net-socket-udp-refactor branch from 1cccf6c to be5ae11 Compare August 23, 2026 14:50

@mkroening mkroening left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

I prefer early returns, so I adjusted the code accordingly. :)

@mkroening
mkroening enabled auto-merge August 23, 2026 14:50
Comment thread src/fd/socket/udp.rs
@mkroening
mkroening disabled auto-merge August 23, 2026 15:01
@fogti
fogti force-pushed the net-socket-udp-refactor branch 3 times, most recently from 7fe5624 to be5ae11 Compare August 23, 2026 16:23
@mkroening
mkroening added this pull request to the merge queue Aug 23, 2026
Merged via the queue into hermit-os:main with commit e6fe528 Aug 23, 2026
44 checks passed
@fogti
fogti deleted the net-socket-udp-refactor branch August 23, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants