From ff5ff501837099d3393fd955acbfa1afde2582c8 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Mon, 12 May 2025 17:41:39 +0200 Subject: [PATCH] Speed up constant string extraction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fish builtin string functions are significantly slower than grep + sed. The final replacement of \' to ' also does not make any sense here, because single quotes appear unescaped in Rust strings. Performance improvement: from 404880 to 44843 (speedup 9.0) Profiling details (from separate runs): Time (μs) Sum (μs) Command 174 404880 > set -a strs (string match -rv 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | string match -rg 'const [A-Z_]*: &str = "(.*)"' | string replace -a "\'" "'") 404706 404706 -> string match -rv 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | string match -rg 'const [A-Z_]*: &str = "(.*)"' | string replace -a "\'" "'" 202 44843 > set -a strs (grep -Ev 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | grep -E 'const [A-Z_]*: &str = "(.*)"' | sed -E -e 's/^.*const [A-Z_]*: &str = "(.*)".*$/\1/' -e "s_\\\'_'_g") 4952 44641 -> grep -Ev 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | grep -E 'const [A-Z_]*: &str = "(.*)"' | sed -E -e 's/^.*const [A-Z_]*: &str = "(.*)".*$/\1/' -e "s_\\\'_'_g" 28716 28716 --> command grep --color=auto $argv 10973 10973 --> command grep --color=auto $argv --- build_tools/fish_xgettext.fish | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build_tools/fish_xgettext.fish b/build_tools/fish_xgettext.fish index 98bf072ed..12ab8d579 100755 --- a/build_tools/fish_xgettext.fish +++ b/build_tools/fish_xgettext.fish @@ -29,8 +29,9 @@ set -l strs (grep -A1 wgettext_static_str <$tmpfile | string replace -a "\'" "'") # Extract any constants -set -a strs (string match -rv 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | - string match -rg 'const [A-Z_]*: &str = "(.*)"' | string replace -a "\'" "'") +set -a strs (grep -Ev 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | + grep -E 'const [A-Z_]*: &str = "(.*)"' | + sed -E -e 's/^.*const [A-Z_]*: &str = "(.*)".*$/\1/' -e "s_\\\'_'_g") rm $tmpfile