git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSOC] [QUESTION] ref-filter: can %(raw) implement reuse oi.content?

From
Christian Couder <christian.couder@gmail.com>
Date
Aug 17, 2021, 16:09 UTC
Message-ID
<CAP8UFD0AvakWdpJKBDrEZstVvFOGdjVUkWsBXn7geiUdVzAZGQ@mail.gmail.com>
In-Reply-To
<CAOLTT8TJ_VBh8mreExXHdCFb1e6hB1-Exsn6OFdo2sZNkVFJkA@mail.gmail.com>
Hi,
On Mon, Aug 16, 2021 at 4:00 PM ZheNing Hu <adlternative@gmail.com> wrote:
Show 11 quoted lines
>
> Hi,
>
> In the implementation of %(raw) atom
> (bd0708c7 ref-filter: add %(raw) atom), we use xmemdupz()
> to copy the content of the object. But if we can reuse the content
> of the object?
>
> Since git cat-file --batch needs to use ref-filter
> as the backend, if the object buffer can be reused correctly here,
> we can save a lot of copies and improve its performance by about 6%.
Yeah, that would be great.
Show 21 quoted lines
> Tracing back to the source, the object buffer is allocated from
> oid_object_info_extended(), but in parse_object_buffer() we may lose
> the ownership of the buffer (maybe the buffer is eaten), but I browsed the
> source code of for-each-ref.c or cat-file.c, and I don’t seem to find that the
> buffers which have been eaten are released by the program.
>
> So can we reuse it?
>
> This is what I want to do:
>
> diff --git a/ref-filter.c b/ref-filter.c
> index 93ce2a6ef2..1f6c1daabd 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -1443,7 +1443,7 @@ static void grab_sub_body_contents(struct
> atom_value *val, int deref, struct exp
>                         unsigned long buf_size = data->size;
>
>                         if (atom->u.raw_data.option == RAW_BARE) {
> -                               v->s = xmemdupz(buf, buf_size);
> +                               v->s = buf;

It seems to me that this could work only if 'buf' isn't freed. Have you checked that? Did we leak 'buf' before this patch? Otherwise when are we freeing it?

Show 10 quoted lines
>                                 v->s_size = buf_size;
>                         } else if (atom->u.raw_data.option == RAW_LENGTH) {
>                                 v->s = xstrfmt("%"PRIuMAX, (uintmax_t)buf_size);
> @@ -1768,8 +1768,6 @@ static int get_object(struct ref_array_item
> *ref, int deref, struct object **obj
>         }
>
>         grab_common_values(ref->value, deref, oi);
> -       if (!eaten)
> -               free(oi->content);

This change might not be needed. 'oi->content' seems to come from the 'buf' above, either directly or through a copy, but if we can indeed own the 'buf' completely, then we should be able to dispose of it how we want.

>         return 0;
>  }
Previous: ZheNing HuNext: ZheNing Hu
Message 3 of 14 in “[GSOC] [QUESTION] ref-filter: can %(raw) implement reuse oi.content?”
  1. ZheNing HuAug 16, 2021
  2. Fwd: [GSOC] [QUESTION] ref-filter: can %(raw) implement reuse oi.content?ZheNing Hu, Aug 17, 2021
  3. Christian CouderAug 17, 2021
  4. ZheNing HuAug 18, 2021
  5. Christian CouderAug 18, 2021
  6. ZheNing HuAug 18, 2021
  7. ZheNing HuAug 18, 2021
  8. ZheNing HuAug 19, 2021
  9. Christian CouderAug 20, 2021
  10. ZheNing HuAug 21, 2021
  11. Christian CouderAug 20, 2021
  12. ZheNing HuAug 21, 2021
  13. Christian CouderAug 24, 2021
  14. ZheNing HuAug 25, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.