From: René Scharfe Date: Tue, 25 Oct 2011 18:00:04 GMT Subject: Re: [PATCH] read-cache.c: fix index memory allocation Message-ID: <4EA6F924.6060208@lsrfire.ath.cx> In-Reply-To: Am 25.10.2011 02:01, schrieb Nguyen Thai Ngoc Duy: > On Tue, Oct 25, 2011 at 10:34 AM, Nguyen Thai Ngoc Duy > wrote: >> "git status" is slow. If your changes causes slowdown, it won't likely >> stand out while other fast commands may show (read_cache() is used in >> nearly all commands). So I tested using the following patch. >> >> The result on linux-2.6 shows about 10-20 us slowdown per each >> read_cache() call (30-40 us on webkit, ~50k files) I think your patch >> is good enough :-) > > That was with -O0 by the way. valgrind/massif shows about 200kb memory > more with your patch on webkit repository (7.497 MB vs 7.285 MB), > using the same test, so memory overhead is ok too. We can reduce that a bit -- unless block allocation of index entries is still done somewhere. -- >8 -- Subject: [PATCH 2/1] cache.h: put single NUL at end of struct cache_entry Since in-memory index entries are allocated individually now, the variable slack at the end meant to provide an eight byte alignment is not needed anymore. Have a single NUL instead. This saves zero to seven bytes for an entry, depending on its filename length. Signed-off-by: Rene Scharfe --- cache.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/cache.h b/cache.h index ec0e571..bd106b5 100644 --- a/cache.h +++ b/cache.h @@ -306,7 +306,7 @@ static inline unsigned int canon_mode(unsigned int mode) } #define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7) -#define cache_entry_size(len) flexible_size(cache_entry,len) +#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) #define ondisk_cache_entry_size(len) flexible_size(ondisk_cache_entry,len) #define ondisk_cache_entry_extended_size(len) flexible_size(ondisk_cache_entry_extended,len) -- 1.7.7