Skip to content

[Variant] Optimize the object header generation logic in ObjectBuilder::finish #7978

Closed

Description

@klion26

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

This comes from the comments for pr #7977

One thing I don't love about this approach is the independent calculation of the splice size vs. the bytes that actually get inserted. If they ever disagreed... badness as the insertions underflow or overflow the splice.

Ideally, we could produce an iterator that emits the desired bytes, and the splice itself can guarantee correct behavior. But for that to work the iterator would need to provide an accurate lower bound, so which rules out std::iter::from_fn. Even if we did craft a custom iterator, computing its lower bound would basically be this same calculation all over again. We could also chain together a bunch of iterators, which preserves the lower bound, but somehow I doubt that would be efficient.

Originally posted by @scovich in #7935 (comment)

Or try the other approach that populates the tmp vec with non-zero bytes before splicing it into the main buffer? That's a lot simpler than this iterator-based suggestion, and likely performs better too.

Originally posted by @scovich in #7935 (comment)

Describe the solution you'd like

Avoid the seperation of header size calculation logic and splice action

Describe alternatives you've considered

Additional context

Activity

  1. added
    enhancement
    on Jul 23, 2025
  2. klion26 commented on Jul 23, 2025

    @klion26
    MemberAuthor

    take

  3. changed the title [-]Optimize the object header generation logic in ObjectBuilder::finish[/-] [+][Variant] Optimize the object header generation logic in ObjectBuilder::finish[/+] on Jul 23, 2025
  4. added a commit that references this issue on Jan 9, 2026
    13c43c4
  5. added a commit that references this issue on Jan 15, 2026
    b2f9e42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions