From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] read-cache.c: index format v5 -- 30% smaller/faster than v4
Date: Wed, 13 Feb 2019 14:27:46 -0800 [thread overview]
Message-ID: <xmqq1s4bb9y5.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190213120807.25326-1-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Wed, 13 Feb 2019 19:08:07 +0700")
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> @@ -1749,16 +1750,16 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
> * number of bytes to be stripped from the end of the previous name,
> * and the bytes to append to the result, to come up with its name.
> */
> - int expand_name_field = version == 4;
> + int expand_name_field = version >= 4;
The code can be lazy like this, insteasd of being more descriptive
to say "version 4 or 5", because we won't accept version 6 or later
anyway. Which is OK, I guess.
> if (flags & CE_EXTENDED) {
> - struct ondisk_cache_entry_extended *ondisk2;
> + const struct ondisk_cache_entry_extended *ondisk2 = mmap;
> int extended_flags;
> - ondisk2 = (struct ondisk_cache_entry_extended *)ondisk;
> +
> extended_flags = get_be16(&ondisk2->flags2) << 16;
> /* We do not yet understand any bit out of CE_EXTENDED_FLAGS */
> if (extended_flags & ~CE_EXTENDED_FLAGS)
This part may be a good clean-up regardless.
> @@ -1820,6 +1821,113 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
> return ce;
> }
>
> +enum same_value_bit {
> + DELTA_FORMAT = 1 << 0,
> + SAME_CTIME = 1 << 1, /* only covers sec, not nsec */
> + SAME_MTIME = 1 << 2, /* only covers sec, not nsec */
> + SAME_DEV = 1 << 3,
> + SAME_INO = 1 << 4,
> + SAME_MODE = 1 << 5,
> + SAME_UID = 1 << 6,
> + SAME_GID = 1 << 7,
> + SAME_FLAGS = 1 << 7
> +};
Hmph, really?
> +static struct cache_entry no_previous_ce;
> +
> +static uintmax_t decode_varoffset(const unsigned char **bufp, uintmax_t prev)
> +{
> + uintmax_t val = decode_varint(bufp);
You'd need to make sure (1) !val, which indicates an overflow of the
varint, and (2) bufp after decoding haven't over-read the mmapped
index file. We may want to improve decode_varint() API so that we
can detect truncated data (i.e. (2)) more reliably without first
reading too much. Loose error checking like these would make good
targets for fuzz tests, I suspect.
> + return val & 1 ? prev - (val >> 1) : prev + (val >> 1);
> +}
So, the LSB is used for sign, and the magnitude is shifted by one?
OK.
> +static uintmax_t decode_varoffset_same(const unsigned char **bufp, uintmax_t prev,
> + int same_flag)
> +{
> + return same_flag ? prev : decode_varoffset(bufp, prev);
> +}
> +
> +static uintmax_t decode_varint_same(const unsigned char **bufp, uintmax_t prev,
> + int same_flag)
> +{
> + return same_flag ? prev : decode_varint(bufp);
> +}
Likewise about two error conditions.
> @@ -1967,12 +2075,18 @@ static unsigned long load_cache_entry_block(struct index_state *istate,
> unsigned long src_offset = start_offset;
>
> for (i = offset; i < offset + nr; i++) {
> - struct ondisk_cache_entry *disk_ce;
> struct cache_entry *ce;
> unsigned long consumed;
>
> - disk_ce = (struct ondisk_cache_entry *)(mmap + src_offset);
> - ce = create_from_disk(ce_mem_pool, istate->version, disk_ce, &consumed, previous_ce);
> + if (istate->version <= 4)
> + ce = create_from_disk(ce_mem_pool, istate->version,
> + mmap + src_offset, &consumed,
> + previous_ce);
> + else
> + ce = create_from_disk_v5(ce_mem_pool,
> + mmap + src_offset,
> + &consumed,
> + previous_ce);
This goes directly against the spirit of "create_from_disk()"
internal API, doesn't it? It takes istate->version because it is an
implementation detail of that function how bytes at
&mmap[src_offset] are consumed, possibly using previous_ce
information.
IOW, I think the version dependent switch should go inside that
function and not in this loop.
> +static int ce_write_varint(git_hash_ctx *c, int fd, uintmax_t value)
> +{
> + unsigned char varint[16];
We may want to do something about these "16".
> +static int ce_write_varoffset(git_hash_ctx *c, int fd, uintmax_t next, uintmax_t prev)
> +{
> + unsigned char varint[16];
next prev parent reply other threads:[~2019-02-13 22:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-13 12:08 [PATCH] read-cache.c: index format v5 -- 30% smaller/faster than v4 Nguyễn Thái Ngọc Duy
2019-02-13 22:27 ` Junio C Hamano [this message]
2019-02-14 10:02 ` Ævar Arnfjörð Bjarmason
2019-02-14 10:14 ` Duy Nguyen
2019-02-15 20:22 ` Ben Peart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq1s4bb9y5.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).