Speed up git status via a file system daemon
RFC 1/1 Speed up git status via a file system daemon
Idea taken and code refactored from [1]:
The intent of this patch series is to separate the index-helper logic from the Watchman logic. With very large repos, the percentage of time required to read the index from disk becomes a much smaller percentage of the overall time. The Watchman logic provides a huge performance win for git status (8 seconds vs 12 minutes in our testing) vs the minimal benefits index-helper provides (<1 second).
The current index-helper/watchman combination design requires two daemons, IPC between git and the index-helper, IPC between the index helper and Watchman, shared memory, adding a WAMA extension to the index, etc.
The benefit of splitting these two efforts is a significantly simpler set of changes that give the benefits of utilizing a file system monitoring daemon like Watchman without the additional complexity and overhead associated with index-helper.
The overall design of this refactored patch series is that when the index is read from disk, a hook proc is called that returns the list of potentially changed files. Git then uses this set of files to flag the potentially dirty index and untracked cache entries.
The logic to use this information to limit the scope of which files and directories need to be checked for changes is the largely the same as the original patch series.
One benefit of the hook proc is that it provides a simple, platform independent way to interface with the file system daemon. It does not require another daemon to be running to act as an intermediary between git and the file system daemon to support communicating via named pipes or sockets.
The prototype currently has no mechanism for saving the date/time of the query into the index so the list of potentially changed files grows unbounded. Writing the additional 64 bit date/time data into an optional extension seems like a lot of overhead but changing the on disk index format is expensive as well from a compatibility perspective. Other ideas or suggestions welcome.
Thanks,
Ben
[1] http://article.gmane.org/gmane.comp.version-control.git/298243
--- cache.h | 4 ++ dir.c | 14 ++++- dir.h | 5 ++ read-cache.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 194 insertions(+), 3 deletions(-)
cache.h +4 -0
@@ -182,6 +182,8 @@ struct cache_entry {#define CE_VALID (0x8000)#define CE_STAGESHIFT 12 +#define CE_FSDAEMON_DIRTY (0x0001) +/* * Range 0xFFFF0FFF in ce_flags is divided into * two parts: in-memory flags and on-disk ones.
@@ -338,6 +340,8 @@ struct index_state {struct hashmap dir_hash;unsigned char sha1[20 ];struct untracked_cache *untracked; +/* BENPEART-TODO: persist last_update in the index, use gmtime? */ +time_t last_update; };extern struct index_state the_index;
dir.c +13 -1
@@ -584,7 +584,7 @@ static void trim_trailing_spaces(char *buf)* * If "name" has the trailing slash, it'll be excluded in the search. */ -static struct untracked_cache_dir *lookup_untracked (struct untracked_cache *uc, +struct untracked_cache_dir *lookup_untracked (struct untracked_cache *uc,struct untracked_cache_dir *dir,const char *name,int len) {
@@ -1551,6 +1551,17 @@ static int valid_cached_dir(struct dir_struct *dir,if (!untracked)return 0 ; +if (dir->untracked->use_fsdaemon) { +/* +* With file system daemon, we can trust the untracked cache's +* valid field. +*/ +if (untracked->valid) + goto skip_stat; +else +invalidate_directory (dir->untracked, untracked); + } +if (stat (path->len ? path->buf :"." , &st)) {invalidate_directory (dir->untracked, untracked);memset (&untracked->stat_data,0 ,sizeof (untracked->stat_data));
@@ -1564,6 +1575,7 @@ static int valid_cached_dir(struct dir_struct *dir,return 0 ; } +skip_stat:if (untracked->check_only != !!check_only) {invalidate_directory (dir->untracked, untracked);return 0 ;
dir.h +5 -0
@@ -139,6 +139,8 @@ struct untracked_cache {int gitignore_invalidated;int dir_invalidated;int dir_opened; +/* file system daemon invalidation data */ + unsigned int use_fsdaemon : 1; };struct dir_struct {
@@ -308,4 +310,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned longvoid write_untracked_extension (struct strbuf *out,struct untracked_cache *untracked);void add_untracked_cache (struct index_state *istate);void remove_untracked_cache (struct index_state *istate); +struct untracked_cache_dir *lookup_untracked (struct untracked_cache *uc, +struct untracked_cache_dir *dir, +const char *name,int len);#endif
read-cache.c +172 -2
211 lines not on this page · raw message
Signature · 1 line
2.8.2.windows.1.4.gdf2cc46.dirty