Watchman support for git
Subsystems (2)
The most sigificant patch uses Facebook's watchman daemon[1] to monitor the repository work tree for changes. This makes allows git status to avoid traversing the entire work tree to find changes.
This change requires libwatchman[2], a client library that I wrote for watchman.
While making the watchman change, I also made a change to the index format (contributed here in a separate patch). Index integrity checking uses the same SHA1 algorithm as the rest of git; this is actually relatively slow. It's not a huge part of run-time, but since I wanted to do the same checking for the Watchman filesystem cache (which is about twice as large as the index), I decided to optimize it anyway. I switched to VMAC. VMAC is supposed to be a MAC, but there's no reason it can't be used with a fixed key as a simple integrity check. VMAC is roughly five times faster than SHA1 on my machine; This adds up to a 5% overal speed improvement on git status (depending on the structure of your repo, and about 15% on git diff --cached with no cached changes).
The index format change might be less important with the split index; I haven't investigated that since at the time I wrote these patches, it didn't exist.
Some numbers follow. They are on my laptop, which has 4x i5-2520M processors, 8GB of RAM, and a solid state disk. They're all tested with a hot cache.
Test repository 1: Linux
Linux is about 45k files in 3k directories. The average length of a filename is about 32 bytes.
Git status timing:
no watchman: 125ms
watchman: 90ms
Test repository 2: Superscience
My second test repository (which is a semi-synthetic repo generated from various Twitter internal repos) is somewhat larger than this, and gets a correspondingly larger improvement. It is about 65k files in 20k directories; the average length of a filename is 67 bytes.
Git status timing:
no watchman, index version 4: 370 ms
no watchman, index version 5: 365 ms
watchman, index version 4: 170 ms
watchman, index version 5: 165 ms
[1] https://github.com/facebook/watchman
[2] https://github.com/twitter/libwatchman
PATCH 1/3 After chdir to run grep, return to old directory
From: David Turner <[email protected]>
--- builtin/grep.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
builtin/grep.c +12 -2
@@ -355,15 +355,25 @@ static void run_pager(struct grep_opt *opt, const char *prefix) {struct string_list *path_list = opt->output_priv;const char **argv =xmalloc (sizeof (const char *) * (path_list->nr +1 )); +static char old_directory[PATH_MAX +1 ];int i, status;for (i =0 ; i < path_list->nr; i++) argv[i] = path_list->items[i].string; argv[path_list->nr] =NULL ; -if (prefix &&chdir (prefix)) -die (_ ("Failed to chdir: %s" ), prefix); + +if (prefix) { +if (!getcwd (old_directory,PATH_MAX +1 )) +die (_ ("Failed to get cwd: %s" ), prefix); +if (chdir (prefix)) +die (_ ("Failed to chdir: %s" ), prefix); + } status =run_command_v_opt (argv,RUN_USING_SHELL ); +if (prefix) +if (chdir (old_directory)) +die (_ ("Failed to chdir: %s" ), old_directory); +if (status)exit (status);free (argv);
Signature · 1 line
2.0.0.rc0.31.g69c1a2d
Re: [PATCH 1/3] After chdir to run grep, return to old directory
Quoted 3 lines · [email protected] writes:
From: David Turner <[email protected]>
Signed-off-by David Turner <[email protected]>
Ehh, why?
Quoted 36 lines
--- builtin/grep.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)builtin/grep.c +12
-2@@ -355,15 +355,25 @@ static void run_pager(struct grep_opt *opt, const char *prefix) {struct string_list *path_list = opt->output_priv;const char **argv =xmalloc (sizeof (const char *) * (path_list->nr +1 )); +static char old_directory[PATH_MAX +1 ];int i, status;for (i =0 ; i < path_list->nr; i++) argv[i] = path_list->items[i].string; argv[path_list->nr] =NULL ; -if (prefix &&chdir (prefix)) -die (_ ("Failed to chdir: %s" ), prefix); + +if (prefix) { +if (!getcwd (old_directory,PATH_MAX +1 )) +die (_ ("Failed to get cwd: %s" ), prefix); +if (chdir (prefix)) +die (_ ("Failed to chdir: %s" ), prefix); + } status =run_command_v_opt (argv,RUN_USING_SHELL ); +if (prefix) +if (chdir (old_directory)) +die (_ ("Failed to chdir: %s" ), old_directory); +if (status)exit (status);free (argv);
Re: [PATCH 1/3] After chdir to run grep, return to old directory
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · [email protected] writes:
From: David Turner <[email protected]>
Signed-off-by David Turner <[email protected]>Ehh, why?
Briefly, because otherwise ./t7811-grep-open.sh fails when run under watchman.
This is actually something that I think I'm doing wrong, but I can't see what the sensible way to do it is. When we go to write the fs_cache (in an atexit hook), we use get_fs_cache_file() from environment.c. This is a relative path, because all of the other similar paths are. So if we have chdired, then we fail.
Re: [PATCH 1/3] After chdir to run grep, return to old directory
Quoted 9 lines · David Turner
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · [email protected] writes:
From: David Turner <[email protected]>
Signed-off-by David Turner <[email protected]>Ehh, why?
Quoted 8 lines
Briefly, because otherwise ./t7811-grep-open.sh fails when run under watchman.
This is actually something that I think I'm doing wrong, but I can't see what the sensible way to do it is. When we go to write the
fs_cache(in an atexit hook), we useget_fs_cache_file()fromenvironment.c. This is a relative path, because all of the other similar paths are. So if we have chdired, then we fail.
It sounds like a reasonable code-hygiene thing, too. It looks like we are only doing the chdir to impact the environment of the pager, and affecting the global environment of the parent process is a side effect. It happens not to cause problems now because we exit immediately, but anybody who adds code after run_pager has to deal with it (and that is basically what you are doing here). Something like cleaning up tempfiles would be similarly affected.
That being said, this really seems like something that the run-command interface should be doing, since it can handle the chdir in the forked child. And indeed, it seems to support that.
Maybe:
-- >8 --
Subject: grep: use run-command's "dir" option for --open-files-in-pager
Git generally changes directory to the repository root on startup. When running "grep --open-files-in-pager" from a subdirectory, we chdir back to the original directory before running the pager, so that we can feed the relative pathnames to the pager.
We currently do this chdir manually, but we can ask run_command to do it for us. This is fewer lines of code, and as a bonus, the chdir is limited to the child process, which avoids any unexpected surprises for code running after the pager (there isn't any currently, but this is future-proofing).
--- builtin/grep.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
builtin/grep.c +1 -3
@@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix) argv[i] = path_list->items[i].string; argv[path_list->nr] =NULL ; -if (prefix &&chdir (prefix)) -die (_ ("Failed to chdir: %s" ), prefix); - status =run_command_v_opt (argv,RUN_USING_SHELL ); + status =run_command_v_opt_cd_env (argv,RUN_USING_SHELL , prefix,NULL );if (status)exit (status);free (argv);
Signature · 1 line
2.0.0.rc1.436.g03cb729
Re: [PATCH 1/3] After chdir to run grep, return to old directory
This causes my test to pass and generally seems correct to me.
On Tue, 2014-05-06 at 23:00 -0400, Jeff King wrote:
...
Quoted 42 lines
That being said, this really seems like something that the run-command interface should be doing, since it can handle the chdir in the forked child. And indeed, it seems to support that.
Maybe:
-- >8 --
Subject: grep: use run-command's "dir" option for --open-files-in-pagerGit generally changes directory to the repository root on startup. When running "grep --open-files-in-pager" from a subdirectory, we chdir back to the original directory before running the pager, so that we can feed the relative pathnames to the pager.
We currently do this chdir manually, but we can ask
run_commandto do it for us. This is fewer lines of code, and as a bonus, the chdir is limited to the child process, which avoids any unexpected surprises for code running after the pager (there isn't any currently, but this is future-proofing).Signed-off-by Jeff King <[email protected]>--- builtin/grep.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)builtin/grep.c +1
-3@@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix) argv[i] = path_list->items[i].string; argv[path_list->nr] =NULL ; -if (prefix &&chdir (prefix)) -die (_ ("Failed to chdir: %s" ), prefix); - status =run_command_v_opt (argv,RUN_USING_SHELL ); + status =run_command_v_opt_cd_env (argv,RUN_USING_SHELL , prefix,NULL );if (status)exit (status);free (argv);
Re: [PATCH 1/3] After chdir to run grep, return to old directory
Quoted 1 line · David Turner
This causes my test to pass and generally seems correct to me.
Yes, this approach is very sensible, and I'll queue.
But watchman support _should_ be prepared for a program that does not do this. Developing your support in on a codebase with this patch may be sweeping a bug in your code under the rug.
Thanks both for working on your respective changes ;-).
Quoted 45 lines · Jeff King
...
Quoted 42 lines
That being said, this really seems like something that the run-command interface should be doing, since it can handle the chdir in the forked child. And indeed, it seems to support that.
Maybe:
-- >8 --
Subject: grep: use run-command's "dir" option for --open-files-in-pagerGit generally changes directory to the repository root on startup. When running "grep --open-files-in-pager" from a subdirectory, we chdir back to the original directory before running the pager, so that we can feed the relative pathnames to the pager.
We currently do this chdir manually, but we can ask
run_commandto do it for us. This is fewer lines of code, and as a bonus, the chdir is limited to the child process, which avoids any unexpected surprises for code running after the pager (there isn't any currently, but this is future-proofing).Signed-off-by Jeff King <[email protected]>--- builtin/grep.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)builtin/grep.c +1
-3@@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix) argv[i] = path_list->items[i].string; argv[path_list->nr] =NULL ; -if (prefix &&chdir (prefix)) -die (_ ("Failed to chdir: %s" ), prefix); - status =run_command_v_opt (argv,RUN_USING_SHELL ); + status =run_command_v_opt_cd_env (argv,RUN_USING_SHELL , prefix,NULL );if (status)exit (status);free (argv);
Re: [PATCH 1/3] After chdir to run grep, return to old directory
Quoted 9 lines · Junio C Hamano
Quoted 1 line · David Turner
This causes my test to pass and generally seems correct to me.
Yes, this approach is very sensible, and I'll queue.
But watchman support _should_ be prepared for a program that does not do this. Developing your support in on a codebase with this patch may be sweeping a bug in your code under the rug.
I agree that good defensive coding practice would be to not depend on the cwd. That's just what everything in environment.c presently does. I don't want to change the rest of the get_*_file functions, because I don't know what their callers expect of them. Here is my patch to do change just the fs_cache bit:
https://github.com/dturner-tw/git/commit/3fe93aeaee9719ee171a253c49af5126a057c513.patch
(I went ahead and made it part of
the watchman branch on https://github.com/dturner-tw/git.git )
I wanted to just do the fixup where the path is used, but I couldn't see a function for that. If there's no function, that indicates to me that it's probably a bad idea. But maybe I'm just missing it.
PATCH 3/3 Watchman support
In reply to [email protected]From: David Turner <[email protected]>
Add support for filesystem view caching and updating via Facebook's Watchman daemon.
--- Documentation/watchman.txt | 27 ++ Makefile | 9 + cache.h | 4 + config.c | 10 + configure.ac | 8 + diff-lib.c | 70 +++-- dir.c | 210 +++++++++---- dir.h | 18 +- environment.c | 18 +- fs_cache.c | 645 +++++++++++++++++++++++++++++++++++++++ fs_cache.h | 138 +++++++++ hash-io.c | 4 +- read-cache.c | 61 +++- t/t1012-read-tree-df.sh | 2 +- t/t2201-add-update-typechange.sh | 5 +- t/t2204-add-ignored.sh | 6 +- t/t6001-rev-list-graft.sh | 2 +- t/t7900-watchman.sh | 249 +++++++++++++++ t/test-lib.sh | 1 + unpack-trees.c | 2 +- watchman-support.c | 640 ++++++++++++++++++++++++++++++++++++++ watchman-support.h | 10 + 22 files changed, 2045 insertions(+), 94 deletions(-) create mode 100644 Documentation/watchman.txt create mode 100644 fs_cache.c create mode 100644 fs_cache.h create mode 100755 t/t7900-watchman.sh create mode 100644 watchman-support.c create mode 100644 watchman-support.h
Documentation/watchman.txt new file +27 -0
@@ -0,0 +1,27 @@ +How git uses watchman +--------------------- + +Git status (and some other commands) have to determine which files +have changed between the working copy and the index. Ordinarily, this +requires checking every file in the working directory. But if you +have watchman (https://github.com/facebook/watchman) installed, git +can cache the state of the working directory and use watchman to track +file changes, making commands like git status faster. + +set core.usewatchman = true to use watchman. +You can also set +core.watchmansynctimeout = [number of milliseconds] +to change watchman's sync timeout; see the watchman docs for details +on this. You should only change this if you see watchman timeout +error messages. + +Internals +--------- + +The filesystem cache stores information about every file in the +working tree. In almost every case where git calls lstat or +opendir/readdir, the modified file cache can be consulted instead. + +The file system cache is stored on disk in .git/fs_cache. It is +stored very similarly to the index, except without path prefix +compression.
Makefile +9 -0
@@ -667,6 +667,7 @@ LIB_H += ewah/ewok.h LIB_H += ewah/ewok_rlw.h LIB_H += fetch-pack.h LIB_H += fmt-merge-msg.h +LIB_H += fs_cache.h LIB_H += fsck.h LIB_H += gettext.h LIB_H += git-compat-util.h
@@ -808,6 +809,7 @@ LIB_OBJS += ewah/ewah_io.o LIB_OBJS += ewah/ewah_rlw.o LIB_OBJS += exec_cmd.o LIB_OBJS += fetch-pack.o +LIB_OBJS += fs_cache.o LIB_OBJS += fsck.o LIB_OBJS += gettext.o LIB_OBJS += gpg-interface.o
@@ -1445,6 +1447,13 @@ ifdef RUNTIME_PREFIX COMPAT_CFLAGS += -DRUNTIME_PREFIX endif +ifdef USE_WATCHMAN + LIB_H += watchman-support.h + LIB_OBJS += watchman-support.o + EXTLIBS += $(WATCHMAN_LIBS) + BASIC_CFLAGS += -DUSE_WATCHMAN +endif + ifdef NO_PTHREADS BASIC_CFLAGS += -DNO_PTHREADS else
cache.h +4 -0
@@ -272,6 +272,7 @@ struct index_state {struct cache_entry **cache;unsigned int version;unsigned int cache_nr, cache_alloc, cache_changed; +struct fs_cache *fs_cache;struct string_list *resolve_undo;struct cache_tree *cache_tree;struct cache_time timestamp;
@@ -352,6 +353,7 @@ static inline enum object_type object_type(unsigned int mode)#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"#define INDEX_ENVIRONMENT "GIT_INDEX_FILE" +#define FS_CACHE_ENVIRONMENT "GIT_FS_CACHE_FILE"#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE"#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
@@ -594,6 +596,8 @@ extern int check_replace_refs;extern int fsync_object_files;extern int core_preload_index; +extern int core_use_watchman; +extern int core_watchman_sync_timeout;extern int core_apply_sparse_checkout;extern int precomposed_unicode;
config.c +10 -0
@@ -854,6 +854,16 @@ static int git_default_core_config(const char *var, const char *value)return 0 ; } +if (!strcmp (var,"core.usewatchman" )) { + core_use_watchman =git_config_bool (var, value); +return 0 ; + } + +if (!strcmp (var,"core.watchmansynctimeout" )) { + core_watchman_sync_timeout =git_config_int (var, value); +return 0 ; + } +if (!strcmp (var,"core.createobject" )) {if (!strcmp (value,"rename" )) object_creation_mode =OBJECT_CREATION_USES_RENAMES ;
configure.ac +8 -0
@@ -962,6 +962,14 @@ GIT_CONF_SUBST([NO_INITGROUPS]) # # Define NO_ICONV if your libc does not properly support iconv. +# Check for watchman client library + +AC_CHECK_LIB([watchman], [watchman_connect], + [WATCHMAN_LIBS="-lwatchman" + USE_WATCHMAN=YesPlease], + [USE_WATCHMAN=]) +GIT_CONF_SUBST([WATCHMAN_LIBS]) +GIT_CONF_SUBST([USE_WATCHMAN]) ## Other checks. # Define USE_PIC if you need the main git objects to be built with -fPIC
diff-lib.c +53 -17
89 lines not on this page · raw message
dir.c +147 -63
375 lines not on this page · raw message
dir.h +16 -2
@@ -81,7 +81,18 @@ struct dir_struct {DIR_NO_GITLINKS =1 <<3 ,DIR_COLLECT_IGNORED =1 <<4 ,DIR_SHOW_IGNORED_TOO =1 <<5 , - DIR_COLLECT_KILLED_ONLY = 1<<6 +DIR_COLLECT_KILLED_ONLY =1 <<6 , +/* +* Whether the standard excludes are the only file +* excludes which have been set up (if so, we can use +* the fs_cache to optimize is_excluded). +*/ +DIR_STD_EXCLUDES =1 <<7 , +/* +* Excludes should only check the command-line (for +* use with fs_cache) +*/ + DIR_EXCLUDE_CMDL_ONLY = 1<<8 } flags;struct dir_entry **entries;struct dir_entry **ignored;
@@ -138,7 +149,7 @@ extern int match_pathspec(const struct pathspec *pathspec,extern int within_depth (const char *name,int namelen,int depth,int max_depth);extern int fill_directory (struct dir_struct *dir,const struct pathspec *pathspec); -extern int read_directory (struct dir_struct *,const char *path,int len,const struct pathspec *pathspec); +extern int read_directory (struct index_state *index,struct dir_struct *,const char *path,int len,const struct pathspec *pathspec);extern int is_excluded_from_list (const char *pathname,int pathlen,const char *basename,int *dtype,struct exclude_list *el);
@@ -223,4 +234,7 @@ static inline int dir_path_match(const struct dir_entry *ent, has_trailing_dir); } +int get_dtype (struct dirent *de,const char *path,int len); + +#endif
environment.c +17 -1
@@ -73,6 +73,10 @@ char comment_line_char = '#';/* Parallel index stat data preload? */ int core_preload_index =0 ; +/* Use Watchman for faster status queries */ +int core_use_watchman =0 ; +int core_watchman_sync_timeout =300 ; +/* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg;static char *work_tree;
@@ -81,7 +85,7 @@ static const char *namespace;static size_t namespace_len;static const char *git_dir; -static char *git_object_dir, *git_index_file, *git_graft_file; +static char *git_object_dir, *git_index_file, *git_graft_file, *git_fs_cache_file;/* * Repository-local GIT_* environment variables; see cache.h for details.
@@ -143,6 +147,11 @@ static void setup_git_env(void) git_index_file =xmalloc (strlen (git_dir) +7 );sprintf (git_index_file,"%s/index" , git_dir); } + git_fs_cache_file =getenv (FS_CACHE_ENVIRONMENT ); +if (!git_fs_cache_file) { + git_fs_cache_file =xmalloc (strlen (git_dir) +10 ); +sprintf (git_fs_cache_file,"%s/fs_cache" , git_dir); + } git_graft_file =getenv (GRAFT_ENVIRONMENT );if (!git_graft_file) git_graft_file =git_pathdup ("info/grafts" );
@@ -266,6 +275,13 @@ char *get_graft_file(void)return git_graft_file; } +char *get_fs_cache_file (void ) +{ +if (!git_fs_cache_file) +setup_git_env (); +return git_fs_cache_file; +} +int set_git_dir (const char *path) {if (setenv (GIT_DIR_ENVIRONMENT , path,1 ))
fs_cache.c new file +645 -0
645 lines not on this page · raw message
fs_cache.h new file +138 -0
138 lines not on this page · raw message
hash-io.c +2 -2
@@ -154,11 +154,11 @@ void hash_context_init(struct hash_context *ctx, enum hash_io_type type) ctx->write_buffer_len =0 ;switch (type) {case HASH_IO_VMAC : - ctx->c.vc =malloc (sizeof *ctx->c.vc); + ctx->c.vc =xmalloc (sizeof *ctx->c.vc);vmac_set_key (VMAC_KEY , ctx->c.vc);break ;case HASH_IO_SHA1 : - ctx->c.sc =malloc (sizeof *ctx->c.sc); + ctx->c.sc =xmalloc (sizeof *ctx->c.sc);git_SHA1_Init (ctx->c.sc);break ;default :
read-cache.c +59 -2
116 lines not on this page · raw message
t/t1012-read-tree-df.sh +1 -1
@@ -23,7 +23,7 @@ maketree () { } settree () { - rm -f .git/index .git/index.lock && + rm -f .git/index .git/index.lock .git/fs_cache && git clean -d -f -f -q -x && git read-tree "$1" && git checkout-index -f -q -u -a &&
t/t2201-add-update-typechange.sh +4 -1
@@ -124,7 +124,9 @@ test_expect_success diff-index ' test_expect_success 'add -u' ' rm -f ".git/saved-index" && + rm -f ".git/saved-fs_cache" && cp -p ".git/index" ".git/saved-index" && + (test ! -f .git/fs_cache || cp -p ".git/fs_cache" ".git/saved-fs_cache") && git add -u && git ls-files -s >actual && test_cmp expect-final actual
@@ -134,7 +136,8 @@ test_expect_success 'commit -a' ' if test -f ".git/saved-index" then rm -f ".git/index" && - mv ".git/saved-index" ".git/index" + mv ".git/saved-index" ".git/index" && + (test ! -f .git/saved-fs_cache || mv ".git/saved-fs_cache" ".git/fs_cache") fi && git commit -m "second" -a && git ls-files -s >actual &&
t/t2204-add-ignored.sh +3 -3
@@ -18,7 +18,7 @@ test_expect_success setup ' for i in file dir/file dir 'd*' do test_expect_success "no complaints for unignored $i" ' - rm -f .git/index && + rm -f .git/index .git/fs_cache && git add "$i" && git ls-files "$i" >out && test -s out
@@ -28,7 +28,7 @@ done for i in ign dir/ign dir/sub dir/sub/*ign sub/file sub sub/* do test_expect_success "complaints for ignored $i" ' - rm -f .git/index && + rm -f .git/index .git/fs_cache && test_must_fail git add "$i" 2>err && git ls-files "$i" >out && ! test -s out
@@ -39,7 +39,7 @@ do ' test_expect_success "complaints for ignored $i with unignored file" ' - rm -f .git/index && + rm -f .git/index .git/fs_cache && test_must_fail git add "$i" file 2>err && git ls-files "$i" >out && ! test -s out
t/t6001-rev-list-graft.sh +1 -1
@@ -20,7 +20,7 @@ test_expect_success setup ' git commit -a -m "Third in one history." && A2=`git rev-parse --verify HEAD` && - rm -f .git/refs/heads/master .git/index && + rm -f .git/refs/heads/master .git/index .git/fs_cache && echo >fileA fileA again && echo >subdir/fileB fileB again &&
t/t7900-watchman.sh new file +249 -0
249 lines not on this page · raw message
t/test-lib.sh +1 -0
@@ -781,6 +781,7 @@ test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PYTHON" && test_set_prereq PYTHON test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE test -z "$NO_GETTEXT" && test_set_prereq GETTEXT +test -n "$USE_WATCHMAN" && test_set_prereq WATCHMAN # Can we rely on git's output in the C locale? if test -n "$GETTEXT_POISON"
unpack-trees.c +1 -1
@@ -1339,7 +1339,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,memset (&d,0 ,sizeof (d));if (o->dir) d.exclude_per_dir = o->dir->exclude_per_dir; - i =read_directory (&d, pathbuf, namelen+1 ,NULL ); + i =read_directory (o->src_index, &d, pathbuf, namelen+1 ,NULL );if (i)return o->gently ?-1 :add_rejected_path (o,ERROR_NOT_UPTODATE_DIR , ce->name);
watchman-support.c new file +640 -0
640 lines not on this page · raw message
watchman-support.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef WATCHMAN_SUPPORT_H +#define WATCHMAN_SUPPORT_H + +#include "cache.h" +#include <watchman.h> + +int watchman_load_fs_cache (struct index_state *index); +int watchman_reload_fs_cache (struct index_state *index); + +#endif /* WATCHMAN_SUPPORT_H */
Signature · 1 line
2.0.0.rc0.31.g69c1a2d
Quoted 8 lines · dturner@ wrote:
Test repository 1: Linux
Linux is about 45k files in 3k directories. The average length of a filename is about 32 bytes.
Git status timing:
no watchman: 125ms
watchman: 90ms
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
Signature · 1 line
Felipe Contreras
Quoted 6 lines · Felipe Contreras
Quoted 5 lines · dturner@ wrote:
Test repository 1: Linux
Linux is about 45k files in 3k directories. The average length of a filename is about 32 bytes.
Quoted 6 lines
Quoted 3 lines
Git status timing:
no watchman: 125ms
watchman: 90msThat's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Quoted 11 lines · David Turner
Quoted 10 lines · Felipe Contreras
Quoted 8 lines · dturner@ wrote:
Test repository 1: Linux
Linux is about 45k files in 3k directories. The average length of a filename is about 32 bytes.
Git status timing:
no watchman: 125ms
watchman: 90ms
Quoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
Signature · 1 line
Felipe Contreras
Quoted 27 lines · Felipe Contreras
Quoted 11 lines · David Turner
Quoted 10 lines · Felipe Contreras
Quoted 8 lines · dturner@ wrote:
Test repository 1: Linux
Linux is about 45k files in 3k directories. The average length of a filename is about 32 bytes.
Git status timing:
no watchman: 125ms
watchman: 90msQuoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
Converting git repos to hg seems to be incredibly slow. (I have not yet tried doing it with git-remote-hg). But I did find a hg repository for
linux: https://bitbucket.org/orzel/linux-kernel-stable
On this repo, I get:
hg without watchman: 620ms
hg with watchman: 264ms
(compared to 125ms/90ms for git).
The number of syscalls is, perhaps also interesting:
no watchman / with watchman
hg 77773 / 5421 git 59180 / 599
(About 1/3 of hg's syscalls with watchman seem to be loading Python stuff)
Quoted 28 lines · David Turner
Quoted 27 lines · Felipe Contreras
Quoted 11 lines · David Turner
Quoted 10 lines · Felipe Contreras
Quoted 8 lines · dturner@ wrote:
Test repository 1: Linux
Linux is about 45k files in 3k directories. The average length of a filename is about 32 bytes.
Git status timing:
no watchman: 125ms
watchman: 90msQuoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 7 lines
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
Converting git repos to hg seems to be incredibly slow. (I have not yet tried doing it with git-remote-hg).
I haven't profiled the git->hg conversion, only the other way around, but I don't see why it would be slow in git-remote-hg.
The only restriction is that octopus merges are not supported, so you would probably need to find another repository.
Quoted 8 lines
But I did find a hg repository for
linux: https://bitbucket.org/orzel/linux-kernel-stableOn this repo, I get:
hg without watchman: 620ms
hg with watchman: 264ms
(compared to 125ms/90ms for git).
Quoted 7 lines
The number of syscalls is, perhaps also interesting:
no watchman / with watchmanhg 77773 / 5421 git 59180 / 599(About 1/3 of hg's syscalls with watchman seem to be loading Python stuff)
Exactly what I thought :) 28% improvement for Git, 76% improvement for Mercurial. Still, the improvement would be welcome by big companies I bet.
Cheers.
Signature · 1 line
Felipe Contreras
Quoted 15 lines · Felipe Contreras
Quoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
The article at [1] has some details, they claim "For our repository, enabling Watchman integration has made Mercurial's status command more than 5x faster than Git's status command".
[1] https://code.facebook.com/posts/218678814984400/scaling-mercurial-at-facebook/
Signature · 1 line
Sebastian Schuberth
Quoted 17 lines · Sebastian Schuberth
Quoted 15 lines · Felipe Contreras
Quoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 8 lines
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
The article at [1] has some details, they claim "For our repository, enabling Watchman integration has made Mercurial's status command more than 5x faster than Git's status command".
[1] https://code.facebook.com/posts/218678814984400/scaling-mercurial-at-facebook/
a lot of that speed comparison is going to depend on your storage system and the size of your repository.
if you have a high-end enterprise storage system that tracks metadata very differently from the file contents (I've seen some that have rackes worth of SATA drives for contents and then 'small' arrays of a few dozen flash drives for the metadata), and then you have very large repositories (Facebook has everything in a single repo), then you have a perfect storm where something like watchman that talks the proprietary protocol of the storage array can be FAR faster than anything that needs to operate with the standard POSIX calls.
That can easily account for the difference between the facebook announcement and the results presented for normal disks that show an improvement, but with even stock git being faster than improved mercurial.
David Lang
Quoted 39 lines · David Lang
Quoted 17 lines · Sebastian Schuberth
Quoted 15 lines · Felipe Contreras
Quoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 8 lines
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
The article at [1] has some details, they claim "For our repository, enabling Watchman integration has made Mercurial's status command more than 5x faster than Git's status command".
[1] https://code.facebook.com/posts/218678814984400/scaling-mercurial-at-facebook/
a lot of that speed comparison is going to depend on your storage system and the size of your repository.
if you have a high-end enterprise storage system that tracks metadata very differently from the file contents (I've seen some that have rackes worth of SATA drives for contents and then 'small' arrays of a few dozen flash drives for the metadata), and then you have very large repositories (Facebook has everything in a single repo), then you have a perfect storm where something like watchman that talks the proprietary protocol of the storage array can be FAR faster than anything that needs to operate with the standard POSIX calls.
Quoted 3 lines
That can easily account for the difference between the facebook announcement and the results presented for normal disks that show an improvement, but with even stock git being faster than improved mercurial.
As I recall from Facebook's presentation[1] on this (as well as from the discussion on the git mailing list[2]), Facebook's test respository is much larger than any known git repository. In particular, it is larger than WebKit. These performance improvements are not for server-side tasks, but for client-side (e.g. git/hg status). Facebook also made other improvements for the client-server communication, and for log/blame, but these are not relevant to watchman.
It is entirely possible that, as repo size grows, Mercurial with watchman is faster than git without.
With my patches, git status isn't constant-time; it's merely a roughly constant factor faster. My initial design was to make git status constant-time by caching the results of the wt_status_collect calls. But there were so many cases with the various options that I got a bit lost in the wilderness and made a big mess. Maybe I would do better if I tried it again today. And maybe if I just build on top of the untracked-cache code, I would be able to get to constant-time; I'll have to try that at some point.
[1] http://www.youtube.com/watch?v=Dlguc63cRXg
[2] http://comments.gmane.org/gmane.comp.version-control.git/189776
Quoted 40 lines · David Turner
Quoted 39 lines · David Lang
Quoted 17 lines · Sebastian Schuberth
Quoted 15 lines · Felipe Contreras
Quoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 8 lines
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
The article at [1] has some details, they claim "For our repository, enabling Watchman integration has made Mercurial's status command more than 5x faster than Git's status command".
[1] https://code.facebook.com/posts/218678814984400/scaling-mercurial-at-facebook/
a lot of that speed comparison is going to depend on your storage system and the size of your repository.
if you have a high-end enterprise storage system that tracks metadata very differently from the file contents (I've seen some that have rackes worth of SATA drives for contents and then 'small' arrays of a few dozen flash drives for the metadata), and then you have very large repositories (Facebook has everything in a single repo), then you have a perfect storm where something like watchman that talks the proprietary protocol of the storage array can be FAR faster than anything that needs to operate with the standard POSIX calls.
Quoted 8 lines
Quoted 3 lines
That can easily account for the difference between the facebook announcement and the results presented for normal disks that show an improvement, but with even stock git being faster than improved mercurial.
As I recall from Facebook's presentation[1] on this (as well as from the discussion on the git mailing list[2]), Facebook's test respository is much larger than any known git repository. In particular, it is larger than WebKit.
agreed, it's huge, it's the entire codebase history of every tool that they use crammed together in one rep
Quoted 4 lines
These performance improvements are not for server-side tasks, but for client-side (e.g. git/hg status). Facebook also made other improvements for the client-server communication, and for log/blame, but these are not relevant to watchman.
well, in their situation they have shared storage that clients use for this huge repo, so I don't think they have a clear client/server boundry the way you are thinking. Even clients have this huge repo to deal with, and they can do so efficiently by querying the storage device rather than trying to walk the tree or monitor access directly.
Quoted 6 lines
It is entirely possible that, as repo size grows, Mercurial with watchman is faster than git without.
With my patches, git status isn't constant-time; it's merely a roughly constant factor faster. My initial design was to make git status constant-time by caching the results of the
wt_status_collectcalls.
This is what you would have to do with traditional storage. My understanding is that the real benefits of watchman show up when you have non-traditional storage and can take advantage of the knowledge that the storage system gathers for it's own use.
David Lang
Quoted 14 lines
But there were so many cases with the various options that I got a bit lost in the wilderness and made a big mess. Maybe I would do better if I tried it again today. And maybe if I just build on top of the untracked-cache code, I would be able to get to constant-time; I'll have to try that at some point.
[1] http://www.youtube.com/watch?v=Dlguc63cRXg
[2] http://comments.gmane.org/gmane.comp.version-control.git/189776--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 59 lines · David Lang
Quoted 40 lines · David Turner
Quoted 39 lines · David Lang
Quoted 17 lines · Sebastian Schuberth
Quoted 15 lines · Felipe Contreras
Quoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 8 lines
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
The article at [1] has some details, they claim "For our repository, enabling Watchman integration has made Mercurial's status command more than 5x faster than Git's status command".
[1] https://code.facebook.com/posts/218678814984400/scaling-mercurial-at-facebook/
a lot of that speed comparison is going to depend on your storage system and the size of your repository.
if you have a high-end enterprise storage system that tracks metadata very differently from the file contents (I've seen some that have rackes worth of SATA drives for contents and then 'small' arrays of a few dozen flash drives for the metadata), and then you have very large repositories (Facebook has everything in a single repo), then you have a perfect storm where something like watchman that talks the proprietary protocol of the storage array can be FAR faster than anything that needs to operate with the standard POSIX calls.
Quoted 8 lines
Quoted 3 lines
That can easily account for the difference between the facebook announcement and the results presented for normal disks that show an improvement, but with even stock git being faster than improved mercurial.
As I recall from Facebook's presentation[1] on this (as well as from the discussion on the git mailing list[2]), Facebook's test respository is much larger than any known git repository. In particular, it is larger than WebKit.
agreed, it's huge, it's the entire codebase history of every tool that they use crammed together in one rep
Quoted 4 lines
These performance improvements are not for server-side tasks, but for client-side (e.g. git/hg status). Facebook also made other improvements for the client-server communication, and for log/blame, but these are not relevant to watchman.
Quoted 5 lines
well, in their situation they have shared storage that clients use for this huge repo, so I don't think they have a clear client/server boundry the way you are thinking. Even clients have this huge repo to deal with, and they can do so efficiently by querying the storage device rather than trying to walk the tree or monitor access directly.
That's not my understanding from Durham Goode's talk in January. Yes, operations involving history go to the server. But the client also maintains a copy of the working tree, and it is for this that watchman is used. Otherwise, why bother with watchman at all? The server knows when it changes files and could simply maintain its own index of what's changed. Watchman is built on inotify/fsevents -- it doesn't have anything to do with any sort of storage device beyond a vanilla hard drive.
Quoted 66 lines · David Turner
Quoted 59 lines · David Lang
Quoted 40 lines · David Turner
Quoted 39 lines · David Lang
Quoted 17 lines · Sebastian Schuberth
Quoted 15 lines · Felipe Contreras
Quoted 6 lines
Quoted 2 lines
That's very interesting. Do you get similar improvements when doing something similar in Merurial (watchman vs . no watchman).
I have not tried it. My understanding is that this is why Facebook wrote Watchman and added support for it to Mercurial, so I would assume that the improvements are at least this good.
Yeah, my bet is that they are actually much better (because Mercurial can't be so optimized as Git).
I'm interested in this number because if watchman in Git is improving it by 30%, but in Mercurial it's improving it by 100% (made up number), therefore it makes sens that you might want it more if you are using hg, but not so much if you are using git.
Quoted 8 lines
Quoted 4 lines
Also, if similar repositories with Mercurial+watchman are actually faster than Git+watchman, that means that there's room for improvement in your implementation. This is not a big issue at this point of the process, just something nice to know.
The article at [1] has some details, they claim "For our repository, enabling Watchman integration has made Mercurial's status command more than 5x faster than Git's status command".
[1] https://code.facebook.com/posts/218678814984400/scaling-mercurial-at-facebook/
a lot of that speed comparison is going to depend on your storage system and the size of your repository.
if you have a high-end enterprise storage system that tracks metadata very differently from the file contents (I've seen some that have rackes worth of SATA drives for contents and then 'small' arrays of a few dozen flash drives for the metadata), and then you have very large repositories (Facebook has everything in a single repo), then you have a perfect storm where something like watchman that talks the proprietary protocol of the storage array can be FAR faster than anything that needs to operate with the standard POSIX calls.
Quoted 8 lines
Quoted 3 lines
That can easily account for the difference between the facebook announcement and the results presented for normal disks that show an improvement, but with even stock git being faster than improved mercurial.
As I recall from Facebook's presentation[1] on this (as well as from the discussion on the git mailing list[2]), Facebook's test respository is much larger than any known git repository. In particular, it is larger than WebKit.
agreed, it's huge, it's the entire codebase history of every tool that they use crammed together in one rep
Quoted 4 lines
These performance improvements are not for server-side tasks, but for client-side (e.g. git/hg status). Facebook also made other improvements for the client-server communication, and for log/blame, but these are not relevant to watchman.
Quoted 5 lines
well, in their situation they have shared storage that clients use for this huge repo, so I don't think they have a clear client/server boundry the way you are thinking. Even clients have this huge repo to deal with, and they can do so efficiently by querying the storage device rather than trying to walk the tree or monitor access directly.
Quoted 8 lines
That's not my understanding from Durham Goode's talk in January. Yes, operations involving history go to the server. But the client also maintains a copy of the working tree, and it is for this that watchman is used. Otherwise, why bother with watchman at all? The server knows when it changes files and could simply maintain its own index of what's changed. Watchman is built on inotify/fsevents -- it doesn't have anything to do with any sort of storage device beyond a vanilla hard drive.
When you have such a massive repo, your clients aren't storing the data on their local drives, they are accessing the data on a network attached storage (via NFS or through a fuse mount). So they can have their watchman send queries to the storage server to find out what has changed in this massive repo rather than having to walk the directory tree (or try to monitor it for changes on the client machine)
David Lang
Quoted 10 lines · David Lang
Quoted 9 lines
That's not my understanding from Durham Goode's talk in January. Yes, operations involving history go to the server. But the client also maintains a copy of the working tree, and it is for this that watchman is used. Otherwise, why bother with watchman at all? The server knows when it changes files and could simply maintain its own index of what's changed. Watchman is built on inotify/fsevents -- it doesn't have anything to do with any sort of storage device beyond a vanilla hard drive.
Quoted 6 lines
When you have such a massive repo, your clients aren't storing the data on their local drives, they are accessing the data on a network attached storage (via NFS or through a fuse mount). So they can have their watchman send queries to the storage server to find out what has changed in this massive repo rather than having to walk the directory tree (or try to monitor it for changes on the client machine)
Yes, you could do that. But I repeat: that is not what Facebook is actually doing. If it were, they would have no need for inotify or FSEvents, since neither even works with NFS (and a FUSE-based solution would need special support at which point it might as well just implement watchman itself).
Please see this section of Durham Goode's talk for evidence that Facebook is not doing that:
http://www.youtube.com/watch?v=Dlguc63cRXg&t=10m40s
(it's at 10:40 in case that link doesn't work)
Maybe things have changed since at Facebook since Durham gave that talk in January and you have knowledge of that. If so, say so. But from what Facebook has said publicly, this is simply not what's going on.
Quoted 3 lines · On Sat, May 3, 2014 at 6:14 AM, <[email protected]> wrote:
The index format change might be less important with the split index; I haven't investigated that since at the time I wrote these patches, it didn't exist.
This is the worst case scenario of "git status" on webkit.git (182k files, path name 74 byte long on average), hot cache, no SSD
366.379ms gitmodules_config:199 if (read_cache() < 0) die("index file
0.004ms cmd_status:1294 read_cache_preload(&s.pathspec);
488.433ms cmd_status:1295 refresh_index(&the_index, REFRESH_QUIE
456.495ms cmd_status:1299 update_index_if_able(&the_index, &inde
13.088ms wt_status_collect:616 wt_status_collect_changes_worktree(s)
706.926ms wt_status_collect:621 wt_status_collect_changes_index(s)
100.495ms lazy_init_name_hash:136 { int nr; if (istate->name_hash_initia
921.185ms wt_status_collect:622 wt_status_collect_untracked(s)real 0m2.969s user 0m1.943s sys 0m1.021s
Index v4 and split index (and the following read-cache daemon, hopefully) should help reduce numbers of the 1st and 4th lines, I expect to less than 50ms each line. lazy_init_name_hash could be taken away with read-cache daemon also.
core.preloadindex can cut the total number of 2nd and 3rd lines by half. Watchman should help in these two lines, but it should do better than core.preloadindex.
wt_status_collect_changes_index() depends on how damaged cache-tree is (in this case, totally scraped). watchman does not help this either. We need to try to "heal" cache-tree as much as possible to reduce the number.
The last line could be a competition between watchman and my coming "untracked cache" series. I expect to cut the number in that line at least in half without external dependency.
Patch 2/3 did not seem to make it to the list by the way.. initial reaction is storing the list of all paths seems too much, but I'll need to play with it a bit to understand it.
Signature · 1 line
Duy
Quoted 17 lines · Duy Nguyen
Quoted 3 lines · On Sat, May 3, 2014 at 6:14 AM, <[email protected]> wrote:
The index format change might be less important with the split index; I haven't investigated that since at the time I wrote these patches, it didn't exist.
This is the worst case scenario of "git status" on webkit.git (182k files, path name 74 byte long on average), hot cache, no SSD
366.379ms gitmodules_config:199 if (read_cache() < 0) die("index file 0.004ms cmd_status:1294 read_cache_preload(&s.pathspec); 488.433ms cmd_status:1295 refresh_index(&the_index, REFRESH_QUIE 456.495ms cmd_status:1299 update_index_if_able(&the_index, &inde 13.088ms wt_status_collect:616 wt_status_collect_changes_worktree(s) 706.926ms wt_status_collect:621 wt_status_collect_changes_index(s) 100.495ms lazy_init_name_hash:136 { int nr; if (istate->name_hash_initia 921.185ms wt_status_collect:622 wt_status_collect_untracked(s)
Quoted 3 lines
real 0m2.969s user 0m1.943s sys 0m1.021s
For me, those times are:
0m0.581s (no watchman, index v4)
0m0.465s (watchman, index v4)
0m0.445s (watchman, index v5)
That's not huge win on its own, but (a) it's better than nothing and (b) it lays the groundwork for other improvements.
A fair amount (~12%) of the time seems to be spent in zlib; this varies based on how the data is packed IIRC.
Quoted 2 lines
Index v4 and split index (and the following read-cache daemon, hopefully)
Looking at some of the archives for read-cache daemon, it seems to be somewhat similar to watchman, right? But I only saw inotify code; what about Mac OS? Or am I misunderstanding what it is?
Quoted 8 lines
should help reduce numbers of the 1st and 4th lines, I expect to less than 50ms each line.
lazy_init_name_hashcould be taken away with read-cache daemon also.core.preloadindex can cut the total number of 2nd and 3rd lines by half. Watchman should help in these two lines, but it should do better than core.preloadindex.
Quoted 8 lines
wt_status_collect_changes_index()depends on how damaged cache-tree is (in this case, totally scraped). watchman does not help this either. We need to try to "heal" cache-tree as much as possible to reduce the number.The last line could be a competition between watchman and my coming "untracked cache" series. I expect to cut the number in that line at least in half without external dependency.
I hadn't seen the "untracked cached" work (I actually finished these patches a month or so ago but have been waiting for some internal reviews before sending them out). Looks interesting. It seems we use a similar strategy for handling ignores.
Quoted 1 line
Patch 2/3 did not seem to make it to the list by the way..
Thanks for your comments. I just tried again to send patch 2/3. I do actually see the CC of it in my @twitter.com mailbox, but I don't see it in the archives on the web. Do you know if there is a reason the mailing list would reject it? At any rate, the contents may be found at
https://github.com/dturner-tw/git/commit/cf587d54fc72d82a23267348afa2c4b60f14ce51.diff
Quoted 3 lines
initial
reaction is storing the list of all paths seems too much, but I'll need to play with it a bit to understand it.
I wonder if it would make sense to use the untracked cache as the storage strategy, but use watchman as the update strategy.
Quoted 6 lines · David Turner
Quoted 2 lines
Index v4 and split index (and the following read-cache daemon, hopefully)
Looking at some of the archives for read-cache daemon, it seems to be somewhat similar to watchman, right? But I only saw inotify code; what about Mac OS? Or am I misunderstanding what it is?
It's mentioned in [1], the second paragraph, mostly to hide index I/O read cost and the SHA-1 hashing cost in the background. In theory it should work on all platforms that support multiple processes and efficient IPC. It can help load watchman file cache faster too.
Quoted 8 lines
Quoted 3 lines
The last line could be a competition between watchman and my coming "untracked cache" series. I expect to cut the number in that line at least in half without external dependency.
I hadn't seen the "untracked cached" work (I actually finished these patches a month or so ago but have been waiting for some internal reviews before sending them out). Looks interesting. It seems we use a similar strategy for handling ignores.
Yep, mostly the same at the core, except that I exploit directory mtime while you use inotify. Each approach has its own pros and cons, I think. Both should face the same traps in caching (e.g. if you "git rm --cached" a file, that file could be come either untracked, or ignored).
Quoted 6 lines
Quoted 1 line
Patch 2/3 did not seem to make it to the list by the way..
Thanks for your comments. I just tried again to send patch 2/3. I do actually see the CC of it in my @twitter.com mailbox, but I don't see it in the archives on the web. Do you know if there is a reason the mailing list would reject it?
Probably its size, 131K, which is also an indicator to split it (and the third patch) into smaller patches if you want to merge this feature in master eventually.
Quoted 3 lines
At any rate, the contents may be found
at
https://github.com/dturner-tw/git/commit/cf587d54fc72d82a23267348afa2c4b60f14ce51.diff
Good enough for me :)
Quoted 7 lines
Quoted 4 lines
initial
reaction is storing the list of all paths seems too much, but I'll need to play with it a bit to understand it.I wonder if it would make sense to use the untracked cache as the storage strategy, but use watchman as the update strategy.
I'm afraid not. If a directory mtime is changed, which means files/dirs have been added or deleted, the untracked code would fall back to the opendir/readdir/is_excluded dance again on that directory. If we naively do the same using watchman, we lose its advantage that it knows exactly what files/dirs are added/removed. That kind of knowledge can help speed up the dance, which is not stored anywhere in the untracked cache.
We could extend the "read-cache daemon" mentioned above though, to hide all the hard work in the background and present a good view to
git: when a file/dir is added, read-cache daemon classifies the new files/dirs as tracked/untracked/ignore and update its untracked cache in memory. When "git status" asks about the index and untracked cache, it will receive the _updated_ cache (not the on disk version any more) with latest dir mtime so git can verify the cache is perfect and skip opendir/.... All git does is to write the index down in the end to make the updated data permanent. It sounds interesting. But I'm not so sure if it's worth the complexity.
[1] http://article.gmane.org/gmane.comp.version-control.git/247268
Signature · 1 line
Duy
Quoted 4 lines · Duy Nguyen
Quoted 3 lines · David Turner
Quoted 2 lines
Index v4 and split index (and the following read-cache daemon, hopefully)
Quoted 8 lines
Quoted 3 lines
Looking at some of the archives for read-cache daemon, it seems to be somewhat similar to watchman, right? But I only saw inotify code; what about Mac OS? Or am I misunderstanding what it is?
It's mentioned in [1], the second paragraph, mostly to hide index I/O read cost and the SHA-1 hashing cost in the background. In theory it should work on all platforms that support multiple processes and efficient IPC. It can help load watchman file cache faster too.
Yes, that seems like a good idea.
I actually wrote some of a more-complicated, weirder version of this idea. In my version, there was a long-running git daemon process that held the index, the watchman file cache, and also objects loaded from the object database. Other git commands would then send their command-line and arguments over to the daemon, which would run the commands and send stdin/out/err back. Of course, this is complicated because git commands are designed to run then exit, so they often rely on variables being initialized to zero, or fail to free memory. I used the Boehm GC to handle the memory freeing problem. To handle variables that needed to be reinitialized, I used __attribute__(section...) to put them all into one section, which I could save on daemon startup and restore after each command. I also replaced calls to exit() with a function that called longjmp() so the daemon could survive commands failing. Had I continued, I would also have had to track open file descriptors to avoid leaking those.
This was a giant mess that only sort-of worked: it was difficult to track down all of the variables that needed to be reinitialized.
The advantage of my method is that there was somewhat less data to marshall over IPC, and that objects could be easily cached; the disadvantage is complexity, massive code changes, and the fact that it didn't actually totally work at the time I ran out of time.
So I'm really looking forward to trying your version!
Quoted 17 lines
Quoted 8 lines
Quoted 3 lines
The last line could be a competition between watchman and my coming "untracked cache" series. I expect to cut the number in that line at least in half without external dependency.
I hadn't seen the "untracked cached" work (I actually finished these patches a month or so ago but have been waiting for some internal reviews before sending them out). Looks interesting. It seems we use a similar strategy for handling ignores.
Yep, mostly the same at the core, except that I exploit directory mtime while you use inotify. Each approach has its own pros and cons, I think. Both should face the same traps in caching (e.g. if you "git rm --cached" a file, that file could be come either untracked, or ignored).
Quoted 2 lines
Quoted 1 line
Patch 2/3 did not seem to make it to the list by the way..
Quoted 8 lines
Quoted 4 lines
Thanks for your comments. I just tried again to send patch 2/3. I do actually see the CC of it in my @twitter.com mailbox, but I don't see it in the archives on the web. Do you know if there is a reason the mailing list would reject it?
Probably its size, 131K, which is also an indicator to split it (and the third patch) into smaller patches if you want to merge this feature in master eventually.
I would like to merge the feature into master. It works well for me, and some of my colleagues who have tried it out.
I can split the vmac patch into two, but one of them will remain quite large because it contains the code for VMAC and AES, which total a bit over 100k. Since the list will probably reject that, I'll post a link to a repository containing the patches.
I'm not 100% sure how to split the watchman patch up. I could add the fs_cache code and then separately add the watchman code that populates the cache. Do you think there is a need to divide it up beyond this?
Quoted 35 lines · David Turner
Quoted 4 lines · Duy Nguyen
Quoted 3 lines · David Turner
Quoted 2 lines
Index v4 and split index (and the following read-cache daemon, hopefully)
Quoted 8 lines
Quoted 3 lines
Looking at some of the archives for read-cache daemon, it seems to be somewhat similar to watchman, right? But I only saw inotify code; what about Mac OS? Or am I misunderstanding what it is?
It's mentioned in [1], the second paragraph, mostly to hide index I/O read cost and the SHA-1 hashing cost in the background. In theory it should work on all platforms that support multiple processes and efficient IPC. It can help load watchman file cache faster too.
Yes, that seems like a good idea.
I actually wrote some of a more-complicated, weirder version of this idea. In my version, there was a long-running git daemon process that held the index, the watchman file cache, and also objects loaded from the object database. Other git commands would then send their command-line and arguments over to the daemon, which would run the commands and send stdin/out/err back. Of course, this is complicated because git commands are designed to run then exit, so they often rely on variables being initialized to zero, or fail to free memory. I used the Boehm GC to handle the memory freeing problem. To handle variables that needed to be reinitialized, I used
__attribute__(section...)to put them all into one section, which I could save on daemon startup and restore after each command. I also replaced calls toexit()with a function that calledlongjmp()so the daemon could survive commands failing. Had I continued, I would also have had to track open file descriptors to avoid leaking those.This was a giant mess that only sort-of worked: it was difficult to track down all of the variables that needed to be reinitialized.
Quoted 6 lines
The advantage of my method is that there was somewhat less data to marshall over IPC, and that objects could be easily cached; the disadvantage is complexity, massive code changes, and the fact that it didn't actually totally work at the time I ran out of time.
So I'm really looking forward to trying your version!
Hm.. I may face the same problem if I'm not careful. So far I think the daemon only holds index data (with on-disk format, not in-memory), mainly to cut out SHA-1 hashing cost. This is still at the idea phase for me though, nothing is materialized yet.
Quoted 2 lines
I would like to merge the feature into master. It works well for me, and some of my colleagues who have tried it out.
Have you tried to turn watchman on by default, then run it with git test suite? That usually helps.
Quoted 4 lines
I can split the vmac patch into two, but one of them will remain quite large because it contains the code for VMAC and AES, which total a bit over 100k. Since the list will probably reject that, I'll post a link to a repository containing the patches.
With the read-cache deamon, I think hashing cost is less of an issue, so new hashing algorithm becomes less important. If you store the file cache in the deamon's memory only, there's no need to hash anything. But I guess you already tried this.
Quoted 3 lines
I'm not 100% sure how to split the watchman patch up. I could add the
fs_cachecode and then separately add the watchman code that populates the cache. Do you think there is a need to divide it up beyond this?
I'll need to have closer look at your patches to give any suggestions. Although if you don't mind waiting a bit, I can try to put my untracked cache patches in good shape (hopefully in 2 weeks), then you can mostly avoid touching dir.c and reuse my work.
I backed away from watchman support because I was worried about its overhead (of watchman itself, and git/watchman IPC because it's not designed specifically for git), which led me to try optimizing git as much as possible without watchman first, then see how/if watchman can help on top of that. I still think it's a good approach (maybe because it started to make me doubt if watchman could pull a big performance win on top to justify the changes to support it)
Signature · 1 line
Duy
Quoted 5 lines · Duy Nguyen
Quoted 2 lines
I would like to merge the feature into master. It works well for me, and some of my colleagues who have tried it out.
Have you tried to turn watchman on by default, then run it with git test suite? That usually helps.
I have. The tests work run fine under make, but prove sometimes freezes due to an issue in libwatchman which I just fixed (and which I plan to merge as soon as I can get a colleague to look the changes over).
Quoted 9 lines
Quoted 4 lines
I can split the vmac patch into two, but one of them will remain quite large because it contains the code for VMAC and AES, which total a bit over 100k. Since the list will probably reject that, I'll post a link to a repository containing the patches.
With the read-cache deamon, I think hashing cost is less of an issue, so new hashing algorithm becomes less important. If you store the file cache in the deamon's memory only, there's no need to hash anything. But I guess you already tried this.
I agree that with the daemon, the cost is less of an issue, but I am not 100% sure it is a non-issue; consecutive commands that need to read/write the index can still be slowed down.
Quoted 5 lines
Quoted 3 lines
I'm not 100% sure how to split the watchman patch up. I could add the
fs_cachecode and then separately add the watchman code that populates the cache. Do you think there is a need to divide it up beyond this?I'll need to have closer look at your patches to give any suggestions.
I have uploaded a new version (which is about 5-10% faster and which corrects some minor changes) to https://github.com/dturner-tw/git.git on the watchman branch.
Quoted 3 lines
Although if you don't mind waiting a bit, I can try to put my untracked cache patches in good shape (hopefully in 2 weeks), then you can mostly avoid touching
dir.cand reuse my work.
If the untracked cache patches are going to make it into master, then I would of course be willing to rewrite on top of them. But I would also like to have a sense of whether there is any interest in watchman support (outside of Twitter).
For what it's worth, the numbers today for index version 4 are for my superscience repo are:
~380 (no watchman), ~260 (untracked-cache), ~175 (watchman).
That's because untracked-cache still has to stat every directory.
Quoted 7 lines
I backed away from watchman support because I was worried about its overhead (of watchman itself, and git/watchman IPC because it's not designed specifically for git), which led me to try optimizing git as much as possible without watchman first, then see how/if watchman can help on top of that. I still think it's a good approach (maybe because it started to make me doubt if watchman could pull a big performance win on top to justify the changes to support it)
I think on large repositories (especially deeply-nested ones), with the common case of a small number of changes, watchman will end up being a big win. Java tends towards deep nesting (src/main/java/com/twitter/common/...), which is probably why my test repo had the largest speedup (>50%). The IPC overhead might become bad if there were a large number of changes, but so far this has not been an issue for me in testing.
Quoted 4 lines · Duy Nguyen
wt_status_collect_changes_index()depends on how damaged cache-tree is (in this case, totally scraped). watchman does not help this either. We need to try to "heal" cache-tree as much as possible to reduce the number.
On the topic of cache-tree, I notice that unpack_trees() will call discard_index() in the end (or even discard_index() on a merge failure). That destroys cache-tree. unpack_trees() is the core of branch switching, or reset/merge, which I consider frequent operations. Cache-tree destruction is bad for "git diff --cached", "git commit" and maybe more. This discard_index() code was added recently in e28f764 (unpack-trees: plug a memory leak - 2013-08-13). As a workaround, perhaps we only do so when the sequencer is running.
Signature · 1 line
Duy
Quoted 3 lines · Duy Nguyen
This
discard_index()code was added
recently in e28f764 (unpack-trees: plug a memory leak - 2013-08-13). As a workaround, perhaps we only do so when the sequencer is running.
Hmm.. as o->result does not carry cache-tree anyway, the next assignment after discard_index() will "destroy" cache-tree anyway. I wrote and deleted the following sentence, but it looks like I should rewrite again. So if cache-tree has always been destroyed before, be careful when you try to keep cache-tree as cache-tree invalidation code in unpack-trees.c may not be well tested.
Signature · 1 line
Duy
Quoted 3 lines · On Sat, May 3, 2014 at 6:14 AM, <[email protected]> wrote:
The most sigificant patch uses Facebook's watchman daemon[1] to monitor the repository work tree for changes. This makes allows git status to avoid traversing the entire work tree to find changes.
I got "warning: Watchman watch error: Got bad JSON from watchman
get-sockname: '[' or '{' expected near end of file". Any ideas what I did wrong? I'm using watchman.git and libwatchman.git. check-0.9.11 and jansson-2.4 were installed by system (gentoo).
Signature · 1 line
Duy
Quoted 9 lines · Duy Nguyen
Quoted 3 lines · On Sat, May 3, 2014 at 6:14 AM, <[email protected]> wrote:
The most sigificant patch uses Facebook's watchman daemon[1] to monitor the repository work tree for changes. This makes allows git status to avoid traversing the entire work tree to find changes.
I got "warning: Watchman watch error: Got bad JSON from watchman
get-sockname: '[' or '{' expected near end of file". Any ideas what I did wrong? I'm using watchman.git and libwatchman.git. check-0.9.11 and jansson-2.4 were installed by system (gentoo).
What do you get from watchman get-sockname on the command-line? Do the watchman tests pass?
I don't know that I have tested with Jansson 2.4, but I've tried 2.2.1, 2.5, and 2.6.
I also haven't tried on gentoo (I use Ubuntu). But if you still have problems, I can try installing gentoo in a vm and seeing if it's something gentoo-specific.
Quoted 7 lines · David Turner
Quoted 4 lines
I got "warning: Watchman watch error: Got bad JSON from watchman
get-sockname: '[' or '{' expected near end of file". Any ideas what I did wrong? I'm using watchman.git and libwatchman.git. check-0.9.11 and jansson-2.4 were installed by system (gentoo).What do you get from watchman get-sockname on the command-line? Do the watchman tests pass?
Found the problem. "watchman" binary is not in $PATH but popen() did not complain (or it did but your "2>/dev/null" in watchman_connect suppressed it). BTW you need to update the array size of "expressions" in test_watchman_misc().
So without watchman I got
299.871ms read_index_from:1538 if (verify_hdr(hdr, mmap_size) < 0) go 498.205ms cmd_status:1300 refresh_index(&the_index, REFRESH_QUIE 796.050ms wt_status_collect:622 wt_status_collect_untracked(s)
and with watchman ("git status" ran several times to make sure it's cached)
301.950ms read_index_from:1538 if (verify_hdr(hdr, mmap_size) < 0) go
34.918ms read_fs_cache:347 if (verify_hdr(hdr, mmap_size) < 0) go
1564.096ms watchman_load_fs_cache:628 update_fs_cache(istate, result);
161.930ms cmd_status:1300 refresh_index(&the_index, REFRESH_QUIE
251.614ms wt_status_collect:622 wt_status_collect_untracked(s)Given the total time of "git status" without watchman is 1.9s,, update_fs_cache() nearly matches that number alone. All that is spent in the exclude update code in the function, but if you do last_excluding_matching() anyway, why cache it?
I think we're paying lookup cost in refresh_index(). I forced CE_VALID bit on as an experiment and refresh_index() went down to 33ms.
A bit surprised about wt_status_collect_untracked number. I verified that last_excluding_matching() still runs (on the same number of entries like in no-watchman case). Replacing fs_cache_open() in add_excludes_from_file_to_list() to plain open() does not change the number, so we probably won't need that (unless your worktree is filled with .gitignore, which I doubt it's a norm). So about 500ms saved is in opendir/readdir.. A simple/separate opendir/readdir/closedir program confirms that (ugh!).
Signature · 1 line
Duy
Quoted 6 lines · Duy Nguyen
Quoted 5 lines · David Turner
Quoted 4 lines
I got "warning: Watchman watch error: Got bad JSON from watchman
get-sockname: '[' or '{' expected near end of file". Any ideas what I did wrong? I'm using watchman.git and libwatchman.git. check-0.9.11 and jansson-2.4 were installed by system (gentoo).
Quoted 6 lines
Quoted 2 lines
What do you get from watchman get-sockname on the command-line? Do the watchman tests pass?
Found the problem. "watchman" binary is not in $PATH but
popen()did not complain (or it did but your "2>/dev/null" inwatchman_connectsuppressed it).
I should probably not be using popen, since it doesn't offer good error reporting. I'll try to fix that in the next few days.
Quoted 2 lines
BTW you need to update the array size of "expressions" in
test_watchman_misc().
Thanks, fixed.
Quoted 14 lines
So without watchman I got
299.871ms read_index_from:1538 if (verify_hdr(hdr, mmap_size) < 0) go 498.205ms cmd_status:1300 refresh_index(&the_index, REFRESH_QUIE 796.050ms wt_status_collect:622 wt_status_collect_untracked(s)and with watchman ("git status" ran several times to make sure it's cached)
301.950ms read_index_from:1538 if (verify_hdr(hdr, mmap_size) < 0) go 34.918ms read_fs_cache:347 if (verify_hdr(hdr, mmap_size) < 0) go 1564.096ms watchman_load_fs_cache:628 update_fs_cache(istate, result); 161.930ms cmd_status:1300 refresh_index(&the_index, REFRESH_QUIE 251.614ms wt_status_collect:622 wt_status_collect_untracked(s)
Quoted 4 lines
Given the total time of "git status" without watchman is 1.9s,,
update_fs_cache()nearly matches that number alone. All that is spent in the exclude update code in the function, but if you dolast_excluding_matching()anyway, why cache it?
My numbers are different (for my test repository):
---
30.031ms read_index:1386 r = read_index_from(istate, get_index_
71.625ms cmd_status:1302 refresh_index(&the_index, REFRESH_QUIE
259.712ms wt_status_collect:622 wt_status_collect_untracked(s)
----
41.110ms read_index:1386 r = read_index_from(istate, get_index_
9.294ms read_fs_cache:347 if (verify_hdr(hdr, mmap_size) < 0) go
0.173ms watchman_load_fs_cache:628 update_fs_cache(istate, result)
41.901ms read_index:1386 r = read_index_from(istate, get_index_
18.355ms cmd_status:1302 refresh_index(&the_index, REFRESH_QUIE
50.911ms wt_status_collect:622 wt_status_collect_untracked(s)---
I think something must be going wrong with update_fs_cache on your machine. I have a few hypotheses:
1. Maybe watchman isn't fully started up when you run your tests.
2. Maybe there is a bug.
update_fs_cache should only have to update based on what it has learned from watchman. So if no .gitignore has been changed, it should not have to do very much work.
I could take the fe_excluded check and move it above the last_exclude_matching check in fs_cache_is_excluded; it causes t7300 to fail when run under watchman but presumably that's fixable
Quoted 2 lines
I think we're paying lookup cost in
refresh_index(). I forcedCE_VALIDbit on as an experiment andrefresh_index()went down to 33ms.
Yes, it is possible to use Watchman to set CE_VALID as well, and I should probably do that. It's a bit more complicated (at least, I recall running into problems), but probably doable.
Quoted 6 lines
A bit surprised about
wt_status_collect_untrackednumber. I verified thatlast_excluding_matching()still runs (on the same number of entries like in no-watchman case). Replacingfs_cache_open()inadd_excludes_from_file_to_list()to plainopen()does not change the number, so we probably won't need that (unless your worktree is filled with .gitignore, which I doubt it's a norm).
My test repo has a couple hundred of them. Maybe that's unusual? A repo with a lot of projects will tend to have lots of gitignore files, because each project will want to maintain them independently.
Quoted 32 lines · David Turner
Quoted 14 lines
So without watchman I got
299.871ms read_index_from:1538 if (verify_hdr(hdr, mmap_size) < 0) go 498.205ms cmd_status:1300 refresh_index(&the_index, REFRESH_QUIE 796.050ms wt_status_collect:622 wt_status_collect_untracked(s)and with watchman ("git status" ran several times to make sure it's cached)
301.950ms read_index_from:1538 if (verify_hdr(hdr, mmap_size) < 0) go 34.918ms read_fs_cache:347 if (verify_hdr(hdr, mmap_size) < 0) go 1564.096ms watchman_load_fs_cache:628 update_fs_cache(istate, result); 161.930ms cmd_status:1300 refresh_index(&the_index, REFRESH_QUIE 251.614ms wt_status_collect:622 wt_status_collect_untracked(s)Quoted 4 lines
Given the total time of "git status" without watchman is 1.9s,,
update_fs_cache()nearly matches that number alone. All that is spent in the exclude update code in the function, but if you dolast_excluding_matching()anyway, why cache it?My numbers are different (for my test repository):
---
30.031ms read_index:1386 r = read_index_from(istate, get_index_ 71.625ms cmd_status:1302 refresh_index(&the_index, REFRESH_QUIE 259.712ms wt_status_collect:622 wt_status_collect_untracked(s) ---- 41.110ms read_index:1386 r = read_index_from(istate, get_index_ 9.294ms read_fs_cache:347 if (verify_hdr(hdr, mmap_size) < 0) go 0.173ms watchman_load_fs_cache:628 update_fs_cache(istate, result) 41.901ms read_index:1386 r = read_index_from(istate, get_index_ 18.355ms cmd_status:1302 refresh_index(&the_index, REFRESH_QUIE 50.911ms wt_status_collect:622 wt_status_collect_untracked(s)
Quoted 7 lines
---
I think something must be going wrong with
update_fs_cacheon your machine. I have a few hypotheses:1. Maybe watchman isn't fully started up when you run your tests.
2. Maybe there is a bug.
It's probably me doing something wrong (I ran it more than a couple times so watchman must have loaded the whole thing). I got small numbers in update_fs_cache() now.
Quoted 10 lines
Quoted 6 lines
A bit surprised about
wt_status_collect_untrackednumber. I verified thatlast_excluding_matching()still runs (on the same number of entries like in no-watchman case). Replacingfs_cache_open()inadd_excludes_from_file_to_list()to plainopen()does not change the number, so we probably won't need that (unless your worktree is filled with .gitignore, which I doubt it's a norm).My test repo has a couple hundred of them. Maybe that's unusual? A repo with a lot of projects will tend to have lots of gitignore files, because each project will want to maintain them independently.
I tried the worst case, every directory had an empty .gitignore. The numbers did not change much. And I found out that because add_excludes.. were called twice, not on every .gitignore because of the condition "!(dir->flags & DIR_EXCLUDE_CMDL_ONLY)". So the number of .gitignore does not matter (yet).
This is your quote from above, moved down a bit:
Quoted 7 lines
update_fs_cacheshould only have to update based on what it has learned from watchman. So if no .gitignore has been changed, it should not have to do very much work.I could take the
fe_excludedcheck and move it above thelast_exclude_matchingcheck infs_cache_is_excluded; it causes t7300 to fail when run under watchman but presumably that's fixable
So you exclude files early and make the real read_directory() pass do pretty much nothing. This is probably not a good idea. Assume that I touch $TOP/.gitignore then do something other than "git status" (or "git add") then I have to pay read_directory() cost.
Back to the open vs fs_cache_open and the number of .gitignore files above. I touch $TOP/.gitignore then do "git status" to make it read all .gitignore files (6k of them) and change between open and fs_cache_open. I think the numbers still do not make any visible difference (~1620-1630ms).
Signature · 1 line
Duy
Quoted 6 lines · Duy Nguyen
This is your quote from above, moved down a bit:
Quoted 4 lines
update_fs_cacheshould only have to update based on what it has learned from watchman. So if no .gitignore has been changed, it should not have to do very much work.
Quoted 8 lines
Quoted 3 lines
I could take the
fe_excludedcheck and move it above thelast_exclude_matchingcheck infs_cache_is_excluded; it causes t7300 to fail when run under watchman but presumably that's fixableSo you exclude files early and make the real
read_directory()pass do pretty much nothing. This is probably not a good idea. Assume that I touch $TOP/.gitignore then do something other than "git status" (or "git add") then I have to payread_directory()cost.
I'm not sure I understand this. read_directory does something: it checks the fs_cache (instead of the filesystem) for untracked files.
Quoted 5 lines
Back to the open vs
fs_cache_openand the number of .gitignore files above. I touch $TOP/.gitignore then do "git status" to make it read all .gitignore files (6k of them) and change between open andfs_cache_open. I think the numbers still do not make any visible difference (~1620-1630ms).
Yes, I would expect no win in that case. fs_cache_open will only save time in the common case where there is no .gitignore file, because it saves an open() call. If every possible .gitignore file exists, of course it makes no difference. But also, your processor may be sufficiently slow that the context-switch penalty for open() is less than the hash table lookup.
For me, the win from fs_cache_open is about 7%.
Quoted 11 lines · David Turner
Quoted 10 lines · Duy Nguyen
This is your quote from above, moved down a bit:
Quoted 7 lines
update_fs_cacheshould only have to update based on what it has learned from watchman. So if no .gitignore has been changed, it should not have to do very much work.I could take the
fe_excludedcheck and move it above thelast_exclude_matchingcheck infs_cache_is_excluded; it causes t7300 to fail when run under watchman but presumably that's fixable
Quoted 7 lines
Quoted 4 lines
So you exclude files early and make the real
read_directory()pass do pretty much nothing. This is probably not a good idea. Assume that I touch $TOP/.gitignore then do something other than "git status" (or "git add") then I have to payread_directory()cost.I'm not sure I understand this.
read_directorydoes something: it checks thefs_cache(instead of the filesystem) for untracked files.
A lot of commands do read_cache() that that eventually calls update_fs_cache, which does part of read_directory's work (the fe_excluded thing). But not many of those commands actually call read_directory(). It'd better if there's a way to mark that "this .gitignore is changed", but delay the actual exclude processsing until we are sure read_directory() will be used.
Signature · 1 line
Duy
Quoted 20 lines · Duy Nguyen
Quoted 11 lines · David Turner
Quoted 10 lines · Duy Nguyen
This is your quote from above, moved down a bit:
Quoted 7 lines
update_fs_cacheshould only have to update based on what it has learned from watchman. So if no .gitignore has been changed, it should not have to do very much work.I could take the
fe_excludedcheck and move it above thelast_exclude_matchingcheck infs_cache_is_excluded; it causes t7300 to fail when run under watchman but presumably that's fixableQuoted 7 lines
Quoted 4 lines
So you exclude files early and make the real
read_directory()pass do pretty much nothing. This is probably not a good idea. Assume that I touch $TOP/.gitignore then do something other than "git status" (or "git add") then I have to payread_directory()cost.I'm not sure I understand this.
read_directorydoes something: it checks thefs_cache(instead of the filesystem) for untracked files.
Quoted 6 lines
A lot of commands do
read_cache()that that eventually callsupdate_fs_cache, which does part of read_directory's work (thefe_excludedthing). But not many of those commands actually callread_directory(). It'd better if there's a way to mark that "this .gitignore is changed", but delay the actual exclude processsing until we are sureread_directory()will be used.
OK, that would be straighforward, I think.
Quoted 3 lines · On Sat, May 3, 2014 at 6:14 AM, <[email protected]> wrote:
The most sigificant patch uses Facebook's watchman daemon[1] to monitor the repository work tree for changes. This makes allows git status to avoid traversing the entire work tree to find changes.
Some comments on this series. I still haven't been able to run it with watchman so there are many guesses from my side.
First of all, when I set USE_WATCHMAN=Yes in config.mak I expect it to work out of the box, provided that all dependencies are installed. I still need to set WATCHMAN_LIBS for it to build because you only set it with configure script. Would be nice to have a default value for non-configure people too.
I'm not so happy that git now needs to link to libjansson.so and libwatchman.so. I would load libwatchman.so at runtime only when core.usewatchman is on, but this is more of personal taste.
I still prefer my old tracking model, where the majority of lstat() is done by refresh operation and we only need to optimize those lstat calls, not every single lstat statement in the code base. With that in mind, I think you don't need to keep a fs cache on disk at all. All you need to store (in the index) is the clock value from watchman. After we parse the index, we perform a "since" query to get path names (and perhaps "exists" and "mode" for later). Then we set CE_VALID bit on entries that are _not_ in the query result. The remaining items will be lstat'd by git (see [1] and read-cache.c changes onthe next few patches). Assuming the number of updated files is reasonably small, we won't be punished by lookup time. To avoid write time cost due to possible mass CE_VALID change, assuming split-index is already used, we could store this bit separately as an extension and apply it back at read time.
Your changes in dir.c. If I didn't misread it, you still do last_exclude_matching when using fs-cache. That call is where all your CPU is spent and probably explains why you didn't see big perf gain with watchman. I think my untracked cache has dealt correctly with caching in this area. So when you do the watchman query earlier, you also check if any of the directories are updated and force using untracked cache for the rest of the directories.
Hope it helps,
Duy
[1] http://thread.gmane.org/gmane.comp.version-control.git/240339
Quoted 5 lines · Duy Nguyen
Quoted 3 lines · On Sat, May 3, 2014 at 6:14 AM, <[email protected]> wrote:
The most sigificant patch uses Facebook's watchman daemon[1] to monitor the repository work tree for changes. This makes allows git status to avoid traversing the entire work tree to find changes.
Quoted 8 lines
Some comments on this series. I still haven't been able to run it with watchman so there are many guesses from my side.
First of all, when I set USE_WATCHMAN=Yes in config.mak I expect it to work out of the box, provided that all dependencies are installed. I still need to set
WATCHMAN_LIBSfor it to build because you only set it with configure script. Would be nice to have a default value for non-configure people too.
I'll fix that, thanks.
Quoted 3 lines
I'm not so happy that git now needs to link to libjansson.so and libwatchman.so. I would load libwatchman.so at runtime only when core.usewatchman is on, but this is more of personal taste.
I assume you mean something with dlopen? I don't really like that because
(a) nothing else in git works that way and
(b) you would still need the libwatchman headers to build git (or the structs could be copied, but that is ugly).
Quoted 3 lines
I still prefer my old tracking model, where the majority of
lstat()is done by refresh operation and we only need to optimize those lstat calls, not every single lstat statement in the code base.
The lstat calls are only one of the problems. The others are opendir/readdir and open(.gitignore).
Quoted 9 lines
With that in
mind, I think you don't need to keep a fs cache on disk at all. All you need to store (in the index) is the clock value from watchman. After we parse the index, we perform a "since" query to get path names (and perhaps "exists" and "mode" for later). Then we setCE_VALIDbit on entries that are _not_ in the query result. The remaining items will be lstat'd by git (see [1] andread-cache.cchanges on the next few patches). Assuming the number of updated files is reasonably small, we won't be punished by lookup time.
I considered this, but rejected it for a few reasons:
1. We still need to know about the untracked files. I guess we could do an index extension for just that, like your untracked cache.
2. That doesn't eliminate opendir/readdir, I think. Those are a major cost. I did not thoroughly review your patches from January/February, but I didn't notice anything in there about this part of dir.c. Also the cost of open(nonexistent .gitignore) to do ignore processing.
3. Changing a file in the index (e.g. git add) requires clearing the CE_VALID bit; this means that third-party libraries (e.g. jgit) that change the git repo need to understand this extension for correct operation. Maybe that's just the nature of extensions, but it's not something that my present patch set requires.
Quoted 8 lines · David Turner
Quoted 3 lines
I'm not so happy that git now needs to link to libjansson.so and libwatchman.so. I would load libwatchman.so at runtime only when core.usewatchman is on, but this is more of personal taste.
I assume you mean something with dlopen? I don't really like that because
(a) nothing else in git works that way and
(b) you would still need the libwatchman headers to build git (or the structs could be copied, but that is ugly).
And because we don't link to libdl.so anyway, using dlopen means trading libjansson.so and libwatchman.so for libdl.so. And it's uglier. So forget what I wrote.
Quoted 10 lines
Quoted 9 lines
With that in
mind, I think you don't need to keep a fs cache on disk at all. All you need to store (in the index) is the clock value from watchman. After we parse the index, we perform a "since" query to get path names (and perhaps "exists" and "mode" for later). Then we setCE_VALIDbit on entries that are _not_ in the query result. The remaining items will be lstat'd by git (see [1] andread-cache.cchanges on the next few patches). Assuming the number of updated files is reasonably small, we won't be punished by lookup time.
Quoted 3 lines
I considered this, but rejected it for a few reasons:
1. We still need to know about the untracked files. I guess we could do an index extension for just that, like your untracked cache.
Yes. But consider that the number of untracked files is usually small (otherwise 'git status' would look very messy). And your fscache would need to store excluded file list too, which could be a lot bigger (one pair of .[ch] -> one .o). _But_ yours would make 'git status --ignored' work. I don't consider that a major use case for optimization, but people may have different opinions.
Quoted 4 lines
2. That doesn't eliminate opendir/readdir, I think. Those are a major cost. I did not thoroughly review your patches from January/February, but I didn't notice anything in there about this part of
dir.c. Also the cost of open(nonexistent .gitignore) to do ignore processing.
Assuming untracked cache is in use, opendir/readdir is replaced with lstat. And cheap lstat can be solved with watchman without storing anything extra. I solve open(.gitignore) too by checking its stat data with the one in index. If matches, I reuse the version in tree. This does not necessarily make it cheaper, but it increases locality so it might be. _Modified_ .gitignore files have to go through open(.gitignore), but people don't update .gitignore often.
Quoted 5 lines
3. Changing a file in the index (e.g. git add) requires clearing the
CE_VALIDbit; this means that third-party libraries (e.g. jgit) that change the git repo need to understand this extension for correct operation. Maybe that's just the nature of extensions, but it's not something that my present patch set requires.
I don't store CE_VALID on disk. Instead I store a new bit CE_WATCHED. Only after loading and validating against watchman that I turn CE_WATCHED to CE_VALID in memory. So JGit, libgit2 are not confused.
I assume you won't change your mind about this. Which is fine to me. I will still try out my approach with your libwatchman though. Just curious about its performance and complexity, compared to your approach.
A bit off topic, but msys fork has another "fscache" in compat/win32. If you could come up with a different name, maybe it'll be less confusing for them after merging. But this is not a big deal, as this fscache won't work on windows anyway.
Signature · 1 line
Duy
One more thing I think we can solve with watchman is the racy timestamp issue (see 29e4d36 and 407c8eb). Basically if a file is updated within a second (and the system only supports timestamp granuarity down to a second) then git can't know if a file is changed by comparing stat data, so it compares content anyway. With watchman, I think we know that a file is updated or not and can disable racy test. How often this happens and whether it is worth supporting is something to think about.
Signature · 1 line
Duy
Quoted 14 lines · Duy Nguyen
Quoted 10 lines
Quoted 9 lines
With that in
mind, I think you don't need to keep a fs cache on disk at all. All you need to store (in the index) is the clock value from watchman. After we parse the index, we perform a "since" query to get path names (and perhaps "exists" and "mode" for later). Then we setCE_VALIDbit on entries that are _not_ in the query result. The remaining items will be lstat'd by git (see [1] andread-cache.cchanges on the next few patches). Assuming the number of updated files is reasonably small, we won't be punished by lookup time.Quoted 3 lines
I considered this, but rejected it for a few reasons:
1. We still need to know about the untracked files. I guess we could do an index extension for just that, like your untracked cache.
Quoted 6 lines
Yes. But consider that the number of untracked files is usually small (otherwise 'git status' would look very messy). And your fscache would need to store excluded file list too, which could be a lot bigger (one pair of .[ch] -> one .o). _But_ yours would make 'git status --ignored' work. I don't consider that a major use case for optimization, but people may have different opinions.
I don't think --ignored is a major use case. But I do think it's nice to get as much mileage as possible out of a change like this.
Quoted 5 lines
Quoted 4 lines
2. That doesn't eliminate opendir/readdir, I think. Those are a major cost. I did not thoroughly review your patches from January/February, but I didn't notice anything in there about this part of
dir.c. Also the cost of open(nonexistent .gitignore) to do ignore processing.
Quoted 7 lines
Assuming untracked cache is in use, opendir/readdir is replaced with lstat. And cheap lstat can be solved with watchman without storing anything extra. I solve open(.gitignore) too by checking its stat data with the one in index. If matches, I reuse the version in tree. This does not necessarily make it cheaper, but it increases locality so it might be. _Modified_ .gitignore files have to go through open(.gitignore), but people don't update .gitignore often.
Interesting -- if all that actually works, then it's probably the right approach.
Quoted 6 lines
Quoted 5 lines
3. Changing a file in the index (e.g. git add) requires clearing the
CE_VALIDbit; this means that third-party libraries (e.g. jgit) that change the git repo need to understand this extension for correct operation. Maybe that's just the nature of extensions, but it's not something that my present patch set requires.
Quoted 8 lines
I don't store
CE_VALIDon disk. Instead I store a new bitCE_WATCHED. Only after loading and validating against watchman that I turnCE_WATCHEDtoCE_VALIDin memory. So JGit, libgit2 are not confused.I assume you won't change your mind about this. Which is fine to me. I will still try out my approach with your libwatchman though. Just curious about its performance and complexity, compared to your approach.
I am open-minded here. This code is really the first time I have looked at git's internals, and I accept that your way might be better. If you're going to try the watchman version of your approach, then we do a direct comparison. Let me know if there is something I can do to help out on that.
Quoted 4 lines
A bit off topic, but msys fork has another "fscache" in compat/win32. If you could come up with a different name, maybe it'll be less confusing for them after merging. But this is not a big deal, as this fscache won't work on windows anyway.
Does wtcache sounds like a better name?
Quoted 10 lines · David Turner
Quoted 4 lines
I assume you won't change your mind about this. Which is fine to me. I will still try out my approach with your libwatchman though. Just curious about its performance and complexity, compared to your approach.
I am open-minded here. This code is really the first time I have looked at git's internals, and I accept that your way might be better. If you're going to try the watchman version of your approach, then we do a direct comparison. Let me know if there is something I can do to help out on that.
You already helped by publishing your patches (and letting me know about libwatchman) so I can steal bits here and there ;-)
Quoted 7 lines
Quoted 4 lines
A bit off topic, but msys fork has another "fscache" in compat/win32. If you could come up with a different name, maybe it'll be less confusing for them after merging. But this is not a big deal, as this fscache won't work on windows anyway.
Does wtcache sounds like a better name?
Heh i'm bad at naming. But that sounds a bit cryptic. Maybe watchman-cache.c (with funtions starting with prefix wmc_)? Should not worry too much about this though, unless some msysgit guys yell up.
Signature · 1 line
Duy