[libvirt] [PATCH 0/2] Speed up syntax-check

Remove one inefficient regex not applicable to libvirt codebase and join non-reentrant functions into a single regex to reduce the time taken by the two slowest syntax-checks: 4.03 unmarked_diagnostics 4.03 vulnerable_makefile_CVE-2009-4029 4.03 size_of_brackets 4.03 spec_indentation 4.33 require_config_h_first 5.88 prohibit_nonreentrant 7.72 prohibit_undesirable_word_seq This reduces the overall 'make -j9 syntax-check' time for me from ~8s to ~4.5s. Ján Tomko (2): cfg.mk: override gnulib's undesirable_word_seq check cfg.mk: use a single regex for all non-reentrant functions Makefile.nonreentrant | 8 ++++++++ cfg.mk | 18 ++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) -- 2.7.3

The regex in gnulib checks if @xref is at the beginning of a sentence, amongst other things. Since we do not use Texinfo and the regex takes almost twice as much as the rest of our checks, use a custom regex without the @xref chcecks. --- I do not know whether the gnulib regex can be optimized: bad_xref_re_ ?= (?:[\w,:;] +|(?:see|also)\s+)\@xref\{ bad_pxref_re_ ?= (?:[.!?]|(?:see|also))\s+\@pxref\{ prohibit_undesirable_word_seq_RE_ ?= \ /(?:\bcan\s+not\b|$(bad_xref_re_)|$(bad_pxref_re_))/gims Either way, we do not need to check for xref in libvirt. cfg.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cfg.mk b/cfg.mk index 2939458..e7db9a6 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1299,3 +1299,8 @@ exclude_file_name_regexp--sc_prohibit_dt_without_code = \ exclude_file_name_regexp--sc_prohibit_always-defined_macros = \ ^tests/virtestmock.c$$ + +# gnulib's CPU-hungry regex also checks if @xref starts a sequence +# Use a custom regex since we do not use Texinfo +prohibit_undesirable_word_seq_RE_ = \ + /(?:\bcan\s+not\b)/gims -- 2.7.3

On Tue, Jun 14, 2016 at 15:07:27 +0200, Ján Tomko wrote:
The regex in gnulib checks if @xref is at the beginning of a sentence, amongst other things.
Since we do not use Texinfo and the regex takes almost twice as much as the rest of our checks, use a custom regex without the @xref chcecks. --- I do not know whether the gnulib regex can be optimized:
bad_xref_re_ ?= (?:[\w,:;] +|(?:see|also)\s+)\@xref\{ bad_pxref_re_ ?= (?:[.!?]|(?:see|also))\s+\@pxref\{ prohibit_undesirable_word_seq_RE_ ?= \ /(?:\bcan\s+not\b|$(bad_xref_re_)|$(bad_pxref_re_))/gims
Either way, we do not need to check for xref in libvirt.
cfg.mk | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/cfg.mk b/cfg.mk index 2939458..e7db9a6 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1299,3 +1299,8 @@ exclude_file_name_regexp--sc_prohibit_dt_without_code = \
exclude_file_name_regexp--sc_prohibit_always-defined_macros = \ ^tests/virtestmock.c$$ + +# gnulib's CPU-hungry regex also checks if @xref starts a sequence +# Use a custom regex since we do not use Texinfo +prohibit_undesirable_word_seq_RE_ = \ + /(?:\bcan\s+not\b)/gims
Why don't we drop this very pointless check at all?

The prohibit_nonreentrant syntax-check rule spawns a new shell for every non-reentrant function we know, to make it easier to mention the function name in the error message, with the _r appended. Since the line with the offending function is already printed and some of the functions on our list do not have a _r counterpart, compile them into one big regex and use a more generic error message to save time. --- Makefile.nonreentrant | 8 ++++++++ cfg.mk | 13 +++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile.nonreentrant b/Makefile.nonreentrant index 78e26e3..5cc64c0 100644 --- a/Makefile.nonreentrant +++ b/Makefile.nonreentrant @@ -113,3 +113,11 @@ NON_REENTRANT += inet_nsap_ntoa NON_REENTRANT += inet_ntoa NON_REENTRANT += inet_ntop NON_REENTRANT += inet_pton + +# Separate two nothings by space to get one space in a variable +space = +space += +# The space needs to be in a variable otherwise it would be ignored. +# And there must be no spaces around the commas because they would +# not be ignored, logically. +NON_REENTRANT_RE=$(subst $(space),|,$(NON_REENTRANT)) diff --git a/cfg.mk b/cfg.mk index e7db9a6..812e426 100644 --- a/cfg.mk +++ b/cfg.mk @@ -440,18 +440,11 @@ sc_prohibit_PATH_MAX: halt='dynamically allocate paths, do not use PATH_MAX' \ $(_sc_search_regexp) -# Use a subshell for each function, to give the optimal warning message. include $(srcdir)/Makefile.nonreentrant sc_prohibit_nonreentrant: - @fail=0 ; \ - for i in $(NON_REENTRANT) ; \ - do \ - (prohibit="\\<$$i *\\(" \ - halt="use $${i}_r, not $$i" \ - $(_sc_search_regexp) \ - ) || fail=1; \ - done ; \ - exit $$fail + @prohibit="\\<(${NON_REENTRANT_RE}) *\\(" \ + halt="use re-entrant functions (usually ending with _r)" \ + $(_sc_search_regexp) sc_prohibit_select: @prohibit='\<select *\(' \ -- 2.7.3

On Tue, Jun 14, 2016 at 15:07:28 +0200, Ján Tomko wrote:
The prohibit_nonreentrant syntax-check rule spawns a new shell for every non-reentrant function we know, to make it easier to mention the function name in the error message, with the _r appended.
Since the line with the offending function is already printed and some of the functions on our list do not have a _r counterpart, compile them into one big regex and use a more generic error message to save time. --- Makefile.nonreentrant | 8 ++++++++ cfg.mk | 13 +++---------- 2 files changed, 11 insertions(+), 10 deletions(-)
ACK
participants (2)
-
Ján Tomko
-
Peter Krempa