git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/3] gettext: avoid initialization if the locale dir is not present

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 21, 2018, 11:14 UTC
Message-ID
<4ac5d3b9ace6ea8a41e97c036c8122f0d26d3c5a.1524309209.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1524309209.git.johannes.schindelin@gmx.de>

The runtime of a simple `git.exe version` call on Windows is currently dominated by the gettext setup, adding a whopping ~150ms to the ~210ms total.

Given that this cost is added to each and every git.exe invocation goes through common-main's invocation of git_setup_gettext(), and given that scripts have to call git.exe dozens, if not hundreds, of times, this is a substantial performance penalty.

This is particularly pointless when considering that Git for Windows ships without localization (to keep the installer's size to a bearable ~34MB): all that time setting up gettext is for naught.

To be clear, Git for Windows *needs* to be compiled with localization, for the following reasons:

- to allow users to copy add-on localization in case they want it, and
- to fix the nasty error message
	BUG: your vsnprintf is broken (returned -1)
  by using libgettext's override of vsnprintf() that does not share the
  behavior of msvcrt.dll's version of vsnprintf().

So let's be smart about it and skip setting up gettext if the locale directory is not even present.

Since localization might be missing for not-yet-supported locales, this will not break anything.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 gettext.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/gettext.c b/gettext.c
index baba28343c3..701355d66e7 100644
--- a/gettext.c
+++ b/gettext.c
@@ -163,6 +163,9 @@ void git_setup_gettext(void)
 	if (!podir)
 		podir = system_path(GIT_LOCALE_PATH);
 
+	if (!is_directory(podir))
+		return;
+
 	bindtextdomain("git", podir);
 	setlocale(LC_MESSAGES, "");
 	setlocale(LC_TIME, "");
-- 
2.17.0.windows.1.15.gaa56ade3205
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 13 of 21 in “Some add-on patches on top of dj/runtime-prefix”
  1. 0/3 Some add-on patches on top of dj/runtime-prefixJohannes Schindelin, Apr 20, 2018
  2. 1/3 gettext: avoid initialization if the locale dir is not presentJohannes Schindelin, Apr 20, 2018
  3. Ævar Arnfjörð BjarmasonApr 20, 2018
  4. Martin ÅgrenApr 20, 2018
  5. Ævar Arnfjörð BjarmasonApr 20, 2018
  6. Johannes SchindelinApr 20, 2018
  7. Ævar Arnfjörð BjarmasonApr 21, 2018
  8. Johannes SchindelinApr 21, 2018
  9. 2/3 git_setup_gettext: plug memory leakJohannes Schindelin, Apr 20, 2018
  10. 3/3 Avoid multiple PREFIX definitionsJohannes Schindelin, Apr 20, 2018
  11. Philip OakleyApr 22, 2018
  12. 0/3 Some add-on patches on top of dj/runtime-prefixJohannes Schindelin, Apr 21, 2018
  13. 1/3 gettext: avoid initialization if the locale dir is not presentJohannes Schindelin, Apr 21, 2018
  14. 2/3 git_setup_gettext: plug memory leakJohannes Schindelin, Apr 21, 2018
  15. 3/3 Avoid multiple PREFIX definitionsJohannes Schindelin, Apr 21, 2018
  16. Junio C HamanoApr 24, 2018
  17. Junio C HamanoApr 24, 2018
  18. Junio C HamanoApr 24, 2018
  19. Johannes SchindelinApr 24, 2018
  20. Junio C HamanoApr 25, 2018
  21. Johannes SchindelinApr 25, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.