Skip to content

perf: optimize the vector performance in favor of small_vector - #1437

Open
c8ef wants to merge 1 commit into
p4lang:mainfrom
c8ef:remove-short-alloc
Open

perf: optimize the vector performance in favor of small_vector#1437
c8ef wants to merge 1 commit into
p4lang:mainfrom
c8ef:remove-short-alloc

Conversation

@c8ef

@c8ef c8ef commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

I think this PR falls under both codebase modernization and performance optimization:

  1. It replaces the hand-crafted short_alloc utility with a mature, well-tested implementation from Boost (boost::container::small_vector).
  2. It improves the median simple_switch_grpc throughput from 2450 Mbps to 2520 Mbps (~3% gain).

@c8ef
c8ef force-pushed the remove-short-alloc branch from f6862e9 to d4d97b6 Compare August 1, 2026 08:14
@c8ef

c8ef commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Performance numbers from my laptop may not be very reliable. It is very much appreciated if someone can help me verify the result using the original mininet benchmark(simple_switch with thrift) on a more stable hardware.

Still I don't think it will block merging since the cleanup is beneficial and I'm sure it will not have poorer performance.

@c8ef
c8ef marked this pull request as ready for review August 1, 2026 08:27
@c8ef
c8ef force-pushed the remove-short-alloc branch 2 times, most recently from 7ec8d6c to 3fc7d2a Compare August 1, 2026 11:24
@c8ef
c8ef force-pushed the remove-short-alloc branch from 3fc7d2a to a661e5a Compare August 1, 2026 11:24
@fruffy

fruffy commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Hmm, ideally we keep our boost footprint low. Does std::pmr work as well?

@c8ef

c8ef commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, ideally we keep our boost footprint low. Does std::pmr work as well?

I think there are several reasons why small_vector is a better choice here:

  1. using small_vector we can easily support move semantics.
  2. pmr's allocation is a virtual call and cannot easily inlined by compiler.
  3. using small_vector we can get smaller object foodprint than pmr.

@matthewtlam

Copy link
Copy Markdown
Contributor

I'm okay with these changes considering that we aren't importing anything totally new and it simplifies the code. @c8ef where did you get the benchmark values from? Is there a specific benchmark test that we are using?

@c8ef

c8ef commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

where did you get the benchmark values from? Is there a specific benchmark test that we are using?

Mostly I am using the mininet benchmark: https://github.com/p4lang/behavioral-model/blob/main/docs/performance.md#running-the-benchmark

But I am running a modified version since building simple_switch_grpc with bazel is much easier. So it is very much appreciated if someone can help me verify the result using the original mininet benchmark(simple_switch with thrift).

@c8ef

c8ef commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

I also have a question about performance tuning here. After applying this patch, I ran a perf profile using the benchmark. The results indicate that the application is not compute-bound; instead, most of the time is spent in libpcap, which internally calls send/recv. While this makes sense, it's not ideal for performance optimization. Are there any general guidelines or best practices for identifying the true hotspots in this type of application?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants