Skip to content

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

@klion26

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

Metadata

Metadata

Assignees

Labels

enhancementAny new improvement worthy of a entry in the changelog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions