Skip to content

Performance: Deserializing Binary Streams #310

Closed

Description

@mina-asham

Hi, I am working on reading Avro from BigQuery Storage API, the response from BigQuery creates a raw Avro binary output, the Reader implementation doesn't work since it expects the header to be present, so I turned to use from_avro_datum interface, however it killed the performance of the app, upon inspecting this, it turned out that this happens because it's resolving the schema multiple times, see the flamegraph below, but basically ResolvedSchema::try_from is 80.26% of the from_avro_datum call.

Can we expose another interface for from_avro_datum that takes in the ResolvedSchema object instead? Or maybe better, create a binary deserializer, in Java this works by using GenericDatumReader<>(schema) and creating a decoder with DecoderFactory.get().binaryDecoder

Image

Activity

  1. Kriskras99 commented on Oct 9, 2025

    @Kriskras99
    Contributor

    We are currently working on adding async support. Part of that work should make this easier.
    In the meantime this is a workaround:

    struct NoHeader;
    impl HeaderBuilder for NoHeader {
        fn build_header(&self) -> Vec<u8> {
             Vec::new()
        }
    }
    
    let decoder = GenericSingleObjectReader::new_with_header_builder(schema, NoHeader);
    loop {
        let value = decoder.read_value(reader)?;
        println!("{value:?}")
    }
  2. mina-asham commented on Oct 9, 2025

    @mina-asham
    Author

    Thank you, that's a great workaround for now!

  3. mina-asham commented on Oct 9, 2025

    @mina-asham
    Author

    I am noticing another performance bottle neck this time when writing, it's spending most of the time validating the Value, can this be optional or sample based?

    Image
  4. Kriskras99 commented on Oct 9, 2025

    @Kriskras99
    Contributor

    Unfortunately this is currently not possible. This is again something that should be easier with the async work.

  5. Kriskras99 commented on Jan 25, 2026

    @Kriskras99
    Contributor

    We could maybe add a Writer::unvalidated_append, then it is up to the user to ensure the Value is correct for the schema, or to sample their values by sending 1% via Writer::append.

    We would not have to mark it unsafe, as the only consequence of using it wrong is writing invalid data.

    @martin-g what do you think?

  6. Kriskras99 commented on Jan 25, 2026

    @Kriskras99
    Contributor

    @mina-asham if you're using Serde, using Writer::append_ser is a lot faster than doing to_value and then Writer::append.

  7. martin-g commented on Jan 26, 2026

    @martin-g
    Member

    We could maybe add a Writer::unvalidated_append, then it is up to the user to ensure the Value is correct for the schema, or to sample their values by sending 1% via Writer::append.

    Sounds good!
    Maybe behind a cargo feature that the user has to enable explicitly ?

  8. self-assigned this
    on Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions