mbox series

[v2,0/5] Optimize inet_ntop

Message ID 20250604204332.2090912-1-adhemerval.zanella@linaro.org
Headers show
Series Optimize inet_ntop | expand

Message

Adhemerval Zanella Netto June 4, 2025, 8:42 p.m. UTC
Some projects override inet_ntop because the glibc implementation
shows a significant amount of overhead [1][2].  The main culprit
is the internal sprintf, which requires a lot of internal function
calls and is quite slow.  The recent fortifying work required extra
maintenance from these projects (and worse, it might prevent us from
actually using the fortification depending on how the wrapper is
implemented).

To avoid the need to resort to such hacks, this patchset optimizes
inet_ntop.  The resulting performance should be similar to the one
from frr project (and hopefully they might stop it to use a different
implementation).

Changes from v1:
- Fixed bench-build with BENCHSET set to bench-resolv.
- Optimized put_uint8.
- Optimized inet_ntop6.
- Implemented inet_ntoa on top of inet_ntop.

Adhemerval Zanella (5):
  benchtests: Add IPv4 inet_ntop benchmark
  benchtests: Add IPv6 inet_ntop benchmark
  resolve: Proper indent resolv/inet_ntop.c
  resolv: Optimize inet_ntop
  inet: Implement inet_ntoa on top of inet_ntop

 benchtests/Makefile                |    7 +
 benchtests/inet_ntop_ipv4-inputs   | 1003 ++++++++++++++++++++++++++++
 benchtests/inet_ntop_ipv4-source.c |   10 +
 benchtests/inet_ntop_ipv6-inputs   | 1003 ++++++++++++++++++++++++++++
 benchtests/inet_ntop_ipv6-source.c |   10 +
 inet/inet_ntoa.c                   |    7 +-
 resolv/inet_ntop.c                 |  364 +++++-----
 7 files changed, 2229 insertions(+), 175 deletions(-)
 create mode 100644 benchtests/inet_ntop_ipv4-inputs
 create mode 100644 benchtests/inet_ntop_ipv4-source.c
 create mode 100644 benchtests/inet_ntop_ipv6-inputs
 create mode 100644 benchtests/inet_ntop_ipv6-source.c