Mesh: Calculate edges with VectorSet instead of Map #120224

Merged
Hans Goudey merged 11 commits from mod_moder/blender:calc_edges_vector_set into main 2024-04-11 04:33:36 +02:00

Due to legacy reasons (MEdge), edge calculation was being done with idea that edges cannot be temporarily copied.
But today, edges are just int2, so using of edge * instead of edge actually made things worst.
And since OrderedEdge itself is the same thing as int2, there it does not make sense to use Map for edges.
So, now edges are in a hash set. To be able to take index of edges, vector set is used.

The only functional change now is that original edges will be reordered as well. This should be okay just like
an unintentional but stable indices change, but could be avoided by using weak version of OrderedEdge.

For 2'000 x 2'000 x 2'000 cube edges calculation, change is around 3703.47 -> 2911.18 ms.

In order to reduce memory usage, a template parameter is added to VectorSet slots, so they can
use a 32 instead of 64 bit index type. Without that, the performance change is not consistent and
might not be better on a computer with more memory bandwidth.

Co-authored-by: @HooglyBoogly

Due to legacy reasons (`MEdge`), edge calculation was being done with idea that edges cannot be temporarily copied. But today, edges are just `int2`, so using of `edge *` instead of `edge` actually made things worst. And since `OrderedEdge` itself is the same thing as `int2`, there it does not make sense to use `Map` for edges. So, now edges are in a hash set. To be able to take index of edges, vector set is used. The only functional change now is that original edges will be reordered as well. This should be okay just like an unintentional but stable indices change, but could be avoided by using weak version of `OrderedEdge`. For 2'000 x 2'000 x 2'000 cube edges calculation, change is around `3703.47` -> `2911.18` ms. In order to reduce memory usage, a template parameter is added to `VectorSet` slots, so they can use a 32 instead of 64 bit index type. Without that, the performance change is not consistent and might not be better on a computer with more memory bandwidth. Co-authored-by: @HooglyBoogly
Iliya Katushenock added the
Interest
Geometry Nodes
label 2024-04-03 18:52:35 +02:00
Iliya Katushenock added 1 commit 2024-04-03 18:52:45 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2024-04-03 18:52:53 +02:00
Iliya Katushenock requested review from Hans Goudey 2024-04-03 18:57:43 +02:00
Hans Goudey requested changes 2024-04-03 20:24:46 +02:00
Dismissed
Hans Goudey left a comment
Member

I like the code in your PR more, but I can't reproduce the speedup with your calc_edges_becnh.blend file (thanks for including that here BTW!)

BEFORE: Timer 'mesh_calc_edges': (Average: 969.48 ms, Min: 953.64 ms, Last: 972.75 ms)
AFTER:  Timer 'mesh_calc_edges': (Average: 1029.37 ms, Min: 999.79 ms, Last: 1068.50 ms)

Maybe it's worth trying in intermediate version without the change from Map to VectorSet?
Or the problem might be that VectorSet uses int64_t for its indices. Maybe it needs a template
specialization to use int instead for this use case.

I like the code in your PR more, but I can't reproduce the speedup with your `calc_edges_becnh.blend` file (thanks for including that here BTW!) ``` BEFORE: Timer 'mesh_calc_edges': (Average: 969.48 ms, Min: 953.64 ms, Last: 972.75 ms) AFTER: Timer 'mesh_calc_edges': (Average: 1029.37 ms, Min: 999.79 ms, Last: 1068.50 ms) ``` Maybe it's worth trying in intermediate version without the change from `Map` to `VectorSet`? Or the problem might be that `VectorSet` uses `int64_t` for its indices. Maybe it needs a template specialization to use `int` instead for this use case.
@ -120,1 +94,3 @@
}
const Span<OrderedEdge> task_edges = edge_map.as_span();
MutableSpan<int2> result_edges = new_edges.slice(edge_offsets[task_index]);
std::transform(task_edges.begin(),
Member

I'd try changing this to result_edges.copy_from(task_edges.cast<int2>())

I'd try changing this to `result_edges.copy_from(task_edges.cast<int2>())`
Author
Member

Hope OrderedEdge will be refactored to be based on BaseVec<int, 2> to make it more safe.
I also noticed some change by this way: 3517.18 -> 3260.55 ms (befor / after of copy_from).
And next, i noticed that test file is 3x faster for you. This leed in less real-world case, but i wonder if proof of performance still can be visible on 3k cuboid resolution (or more).
I check 2.7k (limit that can be holded by my RAM) both main and latest state of pr: 7.1 -> 6.7s.

It seems i was wrong to point out the performance of this refactoring at the begin, since it mainly legacy reducing, but i still think it would be better if it at least seemed better\

Hope `OrderedEdge` will be refactored to be based on `BaseVec<int, 2>` to make it *more safe*. I also noticed some change by this way: `3517.18` -> `3260.55` ms (befor / after of `copy_from`). And next, i noticed that test file is 3x faster for you. This leed in less real-world case, but i wonder if proof of performance still can be visible on 3k cuboid resolution (or more). I check 2.7k (limit that can be holded by my RAM) both main and latest state of pr: `7.1` -> `6.7`s. It seems i was wrong to point out the performance of this refactoring at the begin, since it mainly legacy reducing, but i still think it would be better if it at least seemed better\
mod_moder marked this conversation as resolved
Author
Member

Thanks for benchmark check, i think speed improvement is related with memory bandwidth (less number of pointers, smaller size of value in map/set container, more trivial loops for read/write).
Might this is small enough change to be not visible (just like in #114733) for you on your pc (so not sure how to prove speedup for you then).

Thanks for benchmark check, i think speed improvement is related with memory bandwidth (less number of pointers, smaller size of value in map/set container, more trivial loops for read/write). Might this is small enough change to be not visible (just like in #114733) for you on your pc (so not sure how to prove speedup for you then).
Iliya Katushenock added 3 commits 2024-04-03 21:30:44 +02:00
Iliya Katushenock requested review from Hans Goudey 2024-04-04 05:45:13 +02:00
Member

Using int for SimpleVectorSetSlot works here and improves the performance for me:
main: Timer 'mesh_calc_edges': (Average: 976.20 ms, Min: 955.63 ms, Last: 1002.69 ms)
PR with change: Timer 'mesh_calc_edges': (Average: 902.40 ms, Min: 885.50 ms, Last: 904.97 ms)

I'll share the diff in chat.

Using `int` for `SimpleVectorSetSlot` works here and improves the performance for me: `main: Timer 'mesh_calc_edges': (Average: 976.20 ms, Min: 955.63 ms, Last: 1002.69 ms)` `PR with change: Timer 'mesh_calc_edges': (Average: 902.40 ms, Min: 885.50 ms, Last: 904.97 ms)` I'll share the diff in chat.
Iliya Katushenock added 2 commits 2024-04-04 21:45:42 +02:00
Author
Member

I can see 3711.94 -> 2911.18 ms changes with apply your changes @HooglyBoogly thanks for spending time for this!

I can see `3711.94` -> `2911.18` ms changes with apply your changes @HooglyBoogly thanks for spending time for this!
Iliya Katushenock added 1 commit 2024-04-04 22:26:26 +02:00
Iliya Katushenock changed title from Refactor: Mesh calculate edges: Use VectorSet instead of Map to Refactoring: Mesh calculate edges: Use VectorSet instead of Map 2024-04-04 22:27:16 +02:00
Hans Goudey changed title from Refactoring: Mesh calculate edges: Use VectorSet instead of Map to Mesh: Calculate edges with VectorSet instead of Map 2024-04-04 22:31:37 +02:00
Hans Goudey requested review from Jacques Lucke 2024-04-04 23:04:11 +02:00
Hans Goudey added 3 commits 2024-04-11 04:28:57 +02:00
Hans Goudey added 1 commit 2024-04-11 04:31:02 +02:00
Hans Goudey approved these changes 2024-04-11 04:31:18 +02:00
Hans Goudey merged commit 6bafe65d28 into main 2024-04-11 04:33:36 +02:00
Iliya Katushenock deleted branch calc_edges_vector_set 2024-04-11 09:48:28 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120224
No description provided.