I have a structure where a parent struct "Vertices" contains a collection for Vertex. This collection of vertex can be a large collection (typical professional use cases can be millions of vertices).
When serializing this, I see that this structure is my current largest bottleneck. I am still thinking what is the best optimization for this case?
#[derive(FromXml, ToXml, PartialEq, Clone, Debug)]
#[xml(ns(CORE_NS), rename = "vertices")]
pub struct Vertices {
pub vertex: Vec<Vertex>,
}
/// A vertex in a triangle mesh
#[derive(FromXml, ToXml, PartialEq, Clone, Debug)]
#[xml(ns(CORE_NS), rename = "vertex")]
pub struct Vertex {
#[xml(attribute)]
pub x: f64,
#[xml(attribute)]
pub y: f64,
#[xml(attribute)]
pub z: f64,
}
So far I see 2 potential optimizations but I have not figured out how to approach them:
- Reduce the overhead of dynamic allocation of the Vec.push() when assembling the Vec by overriding the FromXml impls of Vertices to provide a vec with preallocated memory.
- Try to optimize the parsing for the Vertex struc such that it is deserialized in one go since it is in essence an attribute only Xml element (which should in theory make it easier). However, it is not super clear to me how I can override the FromXml implementation for Vertex such that I can take the whole element content as string.
I am open to suggestions on how else I can tackle this to improve my performance.
I have a structure where a parent struct "Vertices" contains a collection for Vertex. This collection of vertex can be a large collection (typical professional use cases can be millions of vertices).
When serializing this, I see that this structure is my current largest bottleneck. I am still thinking what is the best optimization for this case?
So far I see 2 potential optimizations but I have not figured out how to approach them:
I am open to suggestions on how else I can tackle this to improve my performance.