Skip to content

perf: Optimize mutable mesh partition lookup and bulk vertex copying#721

Open
InboraStudio wants to merge 2 commits into
google:mainfrom
InboraStudio:main
Open

perf: Optimize mutable mesh partition lookup and bulk vertex copying#721
InboraStudio wants to merge 2 commits into
google:mainfrom
InboraStudio:main

Conversation

@InboraStudio

Copy link
Copy Markdown

this PR introduces targeted performance optimizations for intensive stroke generation and mesh updates, resolving known algorithmic bottlenecks.

key changes:

  • O(log N) partition lookup: upgraded MutableMultiMesh::GetPartitionTriangle to use std::upper_bound for binary search, eliminating the O(N) linear scan across partition bounds.
  • exposed raw mutable vertex data: added MutRawVertexData() to MutableMesh to provide safer, low-level access to the underlying byte array, enabling zero-overhead memory transfers.
  • bulk vertex copying: replaced repetitive dynamic dispatch (SetFloatVertexAttribute) inside hot loops in CopyVertexIntoPartition with direct std::memcpy of the vertex byte stride, significantly accelerating bulk mesh modifications.

perf(mutable_mesh): replace linear partition scan with O(log N) upper_bound

perf(mutable_mesh): use memcpy for bulk vertex copies in CopyVertexIntoPartition

feat(geometry): expose MutRawVertexData for fast zero-overhead memory transfers

@sfreilich sfreilich left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these improvements! One slight suggestion about naming.

Comment thread ink/geometry/mutable_mesh.h Outdated
absl::Span<const std::byte> RawVertexData() const { return vertex_data_; }

// Returns the mutable raw data of the mesh's vertices.
absl::Span<std::byte> MutRawVertexData() { return absl::MakeSpan(vertex_data_); }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be named MutableRawVertexData? That's more consistent with naming elsewhere.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done, Fixing it

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.

2 participants