Change how ModelModifier builds the result, i.e.#420
Merged
copybara-service[bot] merged 1 commit intomainfrom Mar 12, 2026
Merged
Change how ModelModifier builds the result, i.e.#420copybara-service[bot] merged 1 commit intomainfrom
ModelModifier builds the result, i.e.#420copybara-service[bot] merged 1 commit intomainfrom
Conversation
c053474 to
3f32bc9
Compare
3f32bc9 to
5ba818d
Compare
* Use `ModelModifier._serialize_model`, i.e. pack the model's `Buffer`s separately, for models with more than 1 MiB of `Buffer`s since we can do a much better job at this than `flatbuffer`'s Python interface, * In `ModelModifier._serialize_model`, serialize the model (without `Buffer`s) only once, and update the `Buffer`s' `offset` and `size` values directly in the packed model, * Compute the exact buffer size and allocate it in one go (don't grow dynamically with `.extend(...)`), using `bytearray` and `memoryview` to avoid intermediate copies. PiperOrigin-RevId: 882765823
5ba818d to
ce26ec6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change how
ModelModifierbuilds the result, i.e.ModelModifier._serialize_model, i.e. pack the model'sBuffers separately, for models with more than 1 MiB ofBuffers since we can do a much better job at this thanflatbuffer's Python interface,ModelModifier._serialize_model, serialize the model (withoutBuffers) only once, and update theBuffers'offsetandsizevalues directly in the packed model,.extend(...)), usingbytearrayandmemoryviewto avoid intermediate copies.