Skip to content

Conversation

@anim001k
Copy link

@anim001k anim001k commented Oct 9, 2025

Summary

Replace full container cloning with element-wise iteration in FieldVector<T> to FieldVector<U> conversion.

Problem

The From<&'a FieldVector<T>> for FieldVector<U> implementation was performing unnecessary full container cloning:

FieldVector(other.clone().into_iter().map(Into::into).collect())

This creates an intermediate Vec<T> allocation before converting elements, causing:

  • Unnecessary memory allocation and copying
  • Temporary memory pressure (doubling memory usage)
  • Performance degradation on large vectors

Solution

Replace with direct iteration over references with element cloning:

FieldVector(other.0.iter().cloned().map(Into::into).collect())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant