Curves: Improve copy and move assignment #117932

Merged
Hans Goudey merged 3 commits from HooglyBoogly/blender:curves-copy-move-assignment into main 2024-02-07 15:40:42 +01:00
Member

Previously the default constructor ran, then the copy or move
assignment. This resulted in extra creations of runtime data,
including allocations of all the shared caches, only for them
to be immediately replaced by the new ones. Move assignment also
didn't clear the source curves completely, which could result in
higher memory usage or worse, extra users for attribute arrays,
which could lead to unnecessary copying.

In a very simple test repeatedly copying a tiny Curves data-block,
I observed a 30% performance improvement.

This also fixes a memory leak of the offsets in the copy assignment.

Previously the default constructor ran, then the copy or move assignment. This resulted in extra creations of runtime data, including allocations of all the shared caches, only for them to be immediately replaced by the new ones. Move assignment also didn't clear the source curves completely, which could result in higher memory usage or worse, extra users for attribute arrays, which could lead to unnecessary copying. In a very simple test repeatedly copying a tiny Curves data-block, I observed a 30% performance improvement. This also fixes a memory leak of the offsets in the copy assignment.
Hans Goudey added 1 commit 2024-02-07 04:12:40 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
c0be6888b0
Curves: Improve copy and move assignment
Previously the default constructor ran, then the copy or move
assignment. This resulted in extra creations of runtime data,
including allocations of all the shared caches, only for them
to be immediately replaced by the new ones. Move assignment also
didn't clear the source curves completely, which could result in
higher memory usage or worse, extra users for attribute arrays,
which could lead to unnecessary copying.

In a very simple test repeatedly copying a tiny Curves data-block,
I observed a 30% performance improvement.

This also fixes a memory leak of the offsets in the copy assignment.
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested review from Jacques Lucke 2024-02-07 04:13:06 +01:00
Raul Fernandez Hernandez approved these changes 2024-02-07 05:18:10 +01:00
Jacques Lucke requested changes 2024-02-07 10:09:41 +01:00
@ -41,6 +41,22 @@ template<typename T> class SharedCache {
/* The cache should be allocated to trigger sharing of the cached data as early as possible. */
cache_ = std::make_shared<CacheData>();
}
SharedCache(const SharedCache &other) : cache_(other.cache_) {}
Member

Why is this necessary. The default special methods should have the same behavior afaik.

Why is this necessary. The default special methods should have the same behavior afaik.
Author
Member

Hmm, yeah this change is unnecessary here. It was from something else I was working on at the same time.

Hmm, yeah this change is unnecessary here. It was from something else I was working on at the same time.
HooglyBoogly marked this conversation as resolved
Hans Goudey added 2 commits 2024-02-07 14:33:53 +01:00
Hans Goudey requested review from Jacques Lucke 2024-02-07 14:35:22 +01:00
Jacques Lucke approved these changes 2024-02-07 14:38:04 +01:00
Jacques Lucke left a comment
Member

@blender-bot build

@blender-bot build
Hans Goudey merged commit 6702f74d0b into main 2024-02-07 15:40:42 +01:00
Hans Goudey deleted branch curves-copy-move-assignment 2024-02-07 15:40:44 +01:00
Sign in to join this conversation.
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 project
No Assignees
3 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#117932
No description provided.