]> git.ipfire.org Git - thirdparty/git.git/commit - attr.c
attr: avoid heavy work when we know the specified attr is not defined
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 27 Dec 2014 23:39:48 +0000 (06:39 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Dec 2014 20:40:48 +0000 (12:40 -0800)
commit06a604e67051b9342c158432a49e42a5440f9280
tree3e12aec4d1febf9d679865949fea89471acc25e0
parentfad32bcd83ec4e4f88013e4a0b05f42e32e2c6f5
attr: avoid heavy work when we know the specified attr is not defined

If we have never seen attr 'X' in any .gitattributes file we have
examined so far, we can be sure that 'X' is not defined. So no need to
go over all the attr stack to look for attr 'X'. This is the purpose
behind this new field maybe_real.

This optimization breaks down if macros are involved because we can't
know for sure what macro would expand to 'X' at attr parsing time. But
if we go the pessimistic way and assume all macros are expanded, we hit
the builtin "binary" macro. At least the "diff" attr defined in this
macro will disable this optimization for git-grep. So we wait until
any attr lines _may_ reference to a macro before we turn this off.

In git.git, this reduces the number of fill_one() call for "git grep
abcdefghi" from ~5348 to 2955. The optimization stops when it reads
t/.gitattributes, which uses 'binary' macro. We could probably reduce
it further by limiting the 'binary' reference to t/ and subdirs only
in this case.

"git grep" is actually a good example to justify this patch. The
command checks "diff" attribute on every file. People usually don't
define this attribute. But they pay the attr lookup penalty anyway
without this patch, proportional to the number of attr lines they have
in repo.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
attr.c