Skip to content

Commit

Permalink
Add -fno-var-tracking-assignments to pysairedis_wrap.cpp when built w…
Browse files Browse the repository at this point in the history
…ith 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]>
  • Loading branch information
mikemallin committed Aug 12, 2024
1 parent 8d0f5eb commit e440f74
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ AC_DEFINE([SAI_GIT_REVISION],
"[m4_esyscmd([echo -n $(cd SAI && git rev-parse --short HEAD || echo 0000000)])]",
[SAI git revision information])

AM_CONDITIONAL(CXX_IS_GCC, test x$CXX = xg++)

AC_OUTPUT(Makefile
meta/Makefile
lib/Makefile
Expand Down
20 changes: 18 additions & 2 deletions pyext/py2/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ SOURCES=../pysairedis.h ../pysairedis.cpp
pkgpython_PYTHON = pysairedis.py __init__.py
pkgpyexec_LTLIBRARIES = _pysairedis.la

#
# -fno-var-tracking-assignments is set for the GCC compiler
# suite to improve build performance. pysairedis_wrap.cpp is
# automatically generated by SWIG, so it's not a big loss.
#
if CXX_IS_GCC
CXXFLAGS_COMPILER = "-fno-var-tracking-assignments"
else
CXXFLAGS_COMPILER = ""
endif

AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I..

BUILT_SOURCES = pysairedis_wrap.cpp

_pysairedis_la_SOURCES = pysairedis_wrap.cpp $(SOURCES)
libpysairedis_wrap_la_SOURCES = pysairedis_wrap.cpp
libpysairedis_wrap_la_CXXFLAGS = -I/usr/include/python$(PYTHON3_VERSION) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(CXXFLAGS_COMPILER) $(NO_CAST_FUNCTION_TYPE)

noinst_LTLIBRARIES = libpysairedis_wrap.la
_pysairedis_la_SOURCES = $(SOURCES)
_pysairedis_la_CXXFLAGS = $(PYTHON2_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(NO_CAST_FUNCTION_TYPE)

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

_pysairedis_la_LIBADD = $(PYTHON2_LIBS)
_pysairedis_la_LIBADD = $(PYTHON2_LIBS) libpysairedis_wrap.la

SWIG_FLAG = -Wall -c++ -python -keyword
if ARCH64
Expand Down
21 changes: 19 additions & 2 deletions pyext/py3/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@ SOURCES=../pysairedis.h ../pysairedis.cpp
pkgpython3_PYTHON = pysairedis.py __init__.py
pkgpy3exec_LTLIBRARIES = _pysairedis.la

#
# -fno-var-tracking-assignments is set for the GCC compiler
# suite to improve build performance. pysairedis_wrap.cpp is
# automatically generated by SWIG, so it's not a big loss.
#
if CXX_IS_GCC
CXXFLAGS_COMPILER = "-fno-var-tracking-assignments"
else
CXXFLAGS_COMPILER = ""
endif

AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I..

BUILT_SOURCES = pysairedis_wrap.cpp

_pysairedis_la_SOURCES = pysairedis_wrap.cpp $(SOURCES)

libpysairedis_wrap_la_SOURCES = pysairedis_wrap.cpp
libpysairedis_wrap_la_CXXFLAGS = -I/usr/include/python$(PYTHON3_VERSION) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(CXXFLAGS_COMPILER) $(NO_CAST_FUNCTION_TYPE)

noinst_LTLIBRARIES = libpysairedis_wrap.la
_pysairedis_la_SOURCES = $(SOURCES)
_pysairedis_la_CXXFLAGS = $(PYTHON3_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \
-Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(NO_CAST_FUNCTION_TYPE)

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

_pysairedis_la_LIBADD = $(PYTHON3_BLDLIBRARY)
_pysairedis_la_LIBADD = $(PYTHON3_BLDLIBRARY) libpysairedis_wrap.la

SWIG_FLAG = -Wall -c++ -python -keyword
if ARCH64
Expand Down

0 comments on commit e440f74

Please sign in to comment.