Skip to content

Commit d6b510c

Browse files
indutnyaddaleax
authored andcommitted
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% Fixes: #7400
1 parent 4e259b2 commit d6b510c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

common.gypi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'node_module_version%': '',
1919

2020
'node_tag%': '',
21+
'node_use_lto%': '',
2122
'uv_library%': 'static_library',
2223

2324
'openssl_fips%': '',
@@ -333,6 +334,13 @@
333334
[ 'node_shared=="true"', {
334335
'cflags': [ '-fPIC' ],
335336
}],
337+
['node_use_lto=="true"', {
338+
'conditions': [ [ 'clang==1', {
339+
'cflags': [ '-flto' ],
340+
}, {
341+
'cflags': [ '-flto=16' ],
342+
} ] ],
343+
}],
336344
],
337345
}],
338346
['OS=="android"', {
@@ -391,6 +399,13 @@
391399
'CLANG_CXX_LIBRARY': 'libc++',
392400
},
393401
}],
402+
['node_use_lto=="true"', {
403+
'xcode_settings': {
404+
'OTHER_CFLAGS': [
405+
'-flto',
406+
],
407+
},
408+
}],
394409
],
395410
}],
396411
['OS=="freebsd" and node_use_dtrace=="true"', {

configure

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ parser.add_option('--with-lttng',
331331
dest='with_lttng',
332332
help='build with Lttng (Only available to Linux)')
333333

334+
parser.add_option('--with-lto',
335+
action='store_true',
336+
dest='use_lto',
337+
help='build with -flto flag (Link Time Optimization)')
338+
334339
parser.add_option('--with-etw',
335340
action='store_true',
336341
dest='with_etw',
@@ -838,6 +843,8 @@ def configure_node(o):
838843
else:
839844
o['variables']['node_use_lttng'] = 'false'
840845

846+
o['variables']['node_use_lto'] = b(options.use_lto)
847+
841848
if options.no_ifaddrs:
842849
o['defines'] += ['SUNOS_NO_IFADDRS']
843850

0 commit comments

Comments
 (0)