Skip to content

Commit 61f1723

Browse files
committed
Add -fno-var-tracking-assignments to pysairedis_wrap.cpp when built with GCC
This improves compilation time by a total of 16m by disabling the GCC feature "Variable Tracking Assingments." The trade-off for disabling this feature is reduced debuggability if anyone needs to go through the object file pysairedis_wrap.o with a debugger. Please see the background below for details. This was identified via the following issue in the SWIG project: - swig/swig#2384 (comment) This is a performance issue in GCC specifically, not CLANG. Results: On a server with the following specifications, the build time for libsairedis went from 20m23s down to 3m50s. CPU: Intel(R) Xeon(R) Gold 6430 RAM: 1Tb DDR5 OS: Ubuntu 22.04 g++: g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 On an Apple MacBook Pro (with a Debian build VM), the build time for libsairedis also dropped significantly from 17m43s down to 3m46s CPU: Apple M3 Pro RAM: 18Gb OS: Debian 12 Bookworm g++: g++ (Debian 12.2.0-14) 12.2.0 Background: - https://gcc.gnu.org/wiki/Var_Tracking_Assignments - https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/developer_guide/ch-debug-vta#ch-debug-vta Signed-off-by: Mike RE Mallin <[email protected]>
1 parent dbcba69 commit 61f1723

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ AC_DEFINE([SAI_GIT_REVISION],
278278
"[m4_esyscmd([echo -n $(cd SAI && git rev-parse --short HEAD || echo 0000000)])]",
279279
[SAI git revision information])
280280

281+
AM_CONDITIONAL(CXX_IS_GCC, test x$CXX = xg++)
282+
281283
AC_OUTPUT(Makefile
282284
meta/Makefile
283285
lib/Makefile

pyext/py2/Makefile.am

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@ SOURCES=../pysairedis.h ../pysairedis.cpp
44
pkgpython_PYTHON = pysairedis.py __init__.py
55
pkgpyexec_LTLIBRARIES = _pysairedis.la
66

7+
#
8+
# -fno-var-tracking-assignments is set for the GCC compiler
9+
# suite to improve build performance. pysairedis_wrap.cpp is
10+
# automatically generated by SWIG, so it's not a big loss.
11+
#
12+
if CXX_IS_GCC
13+
CXXFLAGS_COMPILER = "-fno-var-tracking-assignments"
14+
else
15+
CXXFLAGS_COMPILER = ""
16+
endif
17+
718
AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I..
819

920
BUILT_SOURCES = pysairedis_wrap.cpp
1021

11-
_pysairedis_la_SOURCES = pysairedis_wrap.cpp $(SOURCES)
22+
libpysairedis_wrap_la_SOURCES = pysairedis_wrap.cpp
23+
libpysairedis_wrap_la_CXXFLAGS = $(PYTHON2_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
24+
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(CXXFLAGS_COMPILER) $(NO_CAST_FUNCTION_TYPE)
25+
26+
noinst_LTLIBRARIES = libpysairedis_wrap.la
27+
_pysairedis_la_SOURCES = $(SOURCES)
1228
_pysairedis_la_CXXFLAGS = $(PYTHON2_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
1329
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(NO_CAST_FUNCTION_TYPE)
1430

@@ -18,7 +34,7 @@ _pysairedis_la_LDFLAGS = -module \
1834
-L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \
1935
-lzmq
2036

21-
_pysairedis_la_LIBADD = $(PYTHON2_LIBS)
37+
_pysairedis_la_LIBADD = $(PYTHON2_LIBS) libpysairedis_wrap.la
2238

2339
SWIG_FLAG = -Wall -c++ -python -keyword
2440
if ARCH64

pyext/py3/Makefile.am

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,28 @@ SOURCES=../pysairedis.h ../pysairedis.cpp
44
pkgpython3_PYTHON = pysairedis.py __init__.py
55
pkgpy3exec_LTLIBRARIES = _pysairedis.la
66

7+
#
8+
# -fno-var-tracking-assignments is set for the GCC compiler
9+
# suite to improve build performance. pysairedis_wrap.cpp is
10+
# automatically generated by SWIG, so it's not a big loss.
11+
#
12+
if CXX_IS_GCC
13+
CXXFLAGS_COMPILER = "-fno-var-tracking-assignments"
14+
else
15+
CXXFLAGS_COMPILER = ""
16+
endif
17+
718
AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I..
819

920
BUILT_SOURCES = pysairedis_wrap.cpp
1021

11-
_pysairedis_la_SOURCES = pysairedis_wrap.cpp $(SOURCES)
22+
23+
libpysairedis_wrap_la_SOURCES = pysairedis_wrap.cpp
24+
libpysairedis_wrap_la_CXXFLAGS = $(PYTHON3_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
25+
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(CXXFLAGS_COMPILER) $(NO_CAST_FUNCTION_TYPE)
26+
27+
noinst_LTLIBRARIES = libpysairedis_wrap.la
28+
_pysairedis_la_SOURCES = $(SOURCES)
1229
_pysairedis_la_CXXFLAGS = $(PYTHON3_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
1330
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(NO_CAST_FUNCTION_TYPE)
1431

@@ -18,7 +35,7 @@ _pysairedis_la_LDFLAGS = -module \
1835
-L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \
1936
-lzmq
2037

21-
_pysairedis_la_LIBADD = $(PYTHON3_BLDLIBRARY)
38+
_pysairedis_la_LIBADD = $(PYTHON3_BLDLIBRARY) libpysairedis_wrap.la
2239

2340
SWIG_FLAG = -Wall -c++ -python -keyword
2441
if ARCH64

0 commit comments

Comments
 (0)