From c7353036d4c1d52861cea43b8a1fcff21444083c Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 24 Jun 2016 13:44:00 -0400 Subject: [PATCH] build: introduce `./configure --with-lto` Introduce `--with-lto` configure option to use Link Time Optimization compiler pass in gcc/clang compilers. This flag slightly improves performance of C/C++ heavy code: tls/throughput.js dur="5" type="buf" size="2": ./out/Release/node-flto: 6.1295 ./out/Release/node: 5.6876 ....... 7.77% tls/throughput.js dur="5" type="buf" size="1024": ./out/Release/node-flto: 1567 ./out/Release/node: 1455 ........ 7.70% tls/throughput.js dur="5" type="buf" size="1048576": ./out/Release/node-flto: 4167.8 ./out/Release/node: 4026.7 . 3.50% tls/throughput.js dur="5" type="asc" size="2": ./out/Release/node-flto: 5.5664 ./out/Release/node: 5.0363 ...... 10.52% tls/throughput.js dur="5" type="asc" size="1024": ./out/Release/node-flto: 1462.2 ./out/Release/node: 1336.8 .... 9.38% tls/throughput.js dur="5" type="asc" size="1048576": ./out/Release/node-flto: 3947.5 ./out/Release/node: 3847.4 . 2.60% tls/throughput.js dur="5" type="utf" size="2": ./out/Release/node-flto: 5.5544 ./out/Release/node: 5.0786 ....... 9.37% tls/throughput.js dur="5" type="utf" size="1024": ./out/Release/node-flto: 1328.5 ./out/Release/node: 1255.7 .... 5.80% tls/throughput.js dur="5" type="utf" size="1048576": ./out/Release/node-flto: 3051.1 ./out/Release/node: 2985.1 . 2.21% See: #7400 --- common.gypi | 15 +++++++++++++++ configure | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/common.gypi b/common.gypi index 8da603d00f618e..5cfe457326774c 100644 --- a/common.gypi +++ b/common.gypi @@ -12,6 +12,7 @@ 'python%': 'python', 'node_tag%': '', + 'node_use_lto%': '', 'uv_library%': 'static_library', 'openssl_fips%': '', @@ -290,6 +291,13 @@ ], 'ldflags!': [ '-rdynamic' ], }], + ['node_use_lto=="true"', { + 'conditions': [ [ 'clang==1', { + 'cflags': [ '-flto' ], + }, { + 'cflags': [ '-flto=16' ], + } ] ], + }], ], }], [ 'OS=="android"', { @@ -343,6 +351,13 @@ 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++0x', # -std=gnu++0x }, }], + ['node_use_lto=="true"', { + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-flto', + ], + }, + }], ], }], ['OS=="freebsd" and node_use_dtrace=="true"', { diff --git a/configure b/configure index d622a6f0625a18..833ecbfa0b38ce 100755 --- a/configure +++ b/configure @@ -297,6 +297,11 @@ parser.add_option('--with-lttng', dest='with_lttng', help='build with Lttng (Only available to Linux)') +parser.add_option('--with-lto', + action='store_true', + dest='use_lto', + help='build with -flto flag (Link Time Optimization)') + parser.add_option('--with-etw', action='store_true', dest='with_etw', @@ -777,6 +782,8 @@ def configure_node(o): else: o['variables']['node_use_lttng'] = 'false' + o['variables']['node_use_lto'] = b(options.use_lto) + if options.no_ifaddrs: o['defines'] += ['SUNOS_NO_IFADDRS']