Improve IPAddress::toFullyQualified() CPU performance
authorHenry Filgueiras <henryf@fb.com>
Wed, 6 Aug 2014 18:39:55 +0000 (11:39 -0700)
committerSara Golemon <sgolemon@fb.com>
Thu, 14 Aug 2014 18:49:04 +0000 (11:49 -0700)
commit59bd43f8a546b0fc911b04406ebe7ae8faf7e1f2
treeb02f7a25aa0f9168e00d2d835da4ee96110aeec2
parent1fc548e12813f50591e2c6c2c176f00f9824f597
Improve IPAddress::toFullyQualified() CPU performance

Summary:
Currently IPAddress::toFullyQualified() is fairly slow for IPv6.

Change here implements more lightweight in_addr/in6_addr to string functions.

I also added a benchmark for comparison with inet_ntop.

This makes IPAddressV6::toFullyQualified() significantly faster than inet_ntop, and makes IPAddressV4::str() ~20ns faster than previous impementation (previously ~80ns).

Previous benchmark:
============================================================================
folly/test/IPAddressBenchmark.cpp               relative  time/iter  iters/s
============================================================================
ipv4_to_string_inet_ntop                                   238.91ns    4.19M
ipv4_to_fully_qualified                          289.96%    82.39ns   12.14M
----------------------------------------------------------------------------
ipv6_to_string_inet_ntop                                   780.72ns    1.28M
ipv6_to_fully_qualified                           51.11%     1.53us  654.59K
============================================================================

With this change:
============================================================================
folly/test/IPAddressBenchmark.cpp               relative  time/iter  iters/s
============================================================================
ipv4_to_string_inet_ntop                                   238.06ns    4.20M
ipv4_to_fully_qualified                          364.76%    65.26ns   15.32M
----------------------------------------------------------------------------
ipv6_to_string_inet_ntop                                   770.74ns    1.30M
ipv6_to_fully_qualified                          791.63%    97.36ns   10.27M
============================================================================

Test Plan:
fbconfig folly/test:network_address_test folly/test:network_address_benchmark
fbmake runtests_opt

Reviewed By: simpkins@fb.com

Subscribers: ps, bmatheny

FB internal diff: D1477925

Tasks: 4832974
folly/IPAddressV4.cpp
folly/IPAddressV6.cpp
folly/detail/IPAddress.h
folly/test/IPAddressBenchmark.cpp [new file with mode: 0644]