Anim: use a non-allocating array inside CombinedKeyingResult #120425

Merged
Nathan Vegdahl merged 2 commits from nathanvegdahl/blender:combined_keying_result_no_alloc into main 2024-04-09 17:27:29 +02:00
Member

The data in CombinedKeyingResult was using BLI's Array type, which
heap allocates. However, we know the array size at compile time,
and therefore can use std::array instead, as suggested in Array's
documentation. This makes CombinedKeyingResult a lighter weight
plain-old-data class.

The data in CombinedKeyingResult was using BLI's Array type, which heap allocates. However, we know the array size at compile time, and therefore can use std::array instead, as suggested in Array's documentation. This makes CombinedKeyingResult a lighter weight plain-old-data class.
Nathan Vegdahl added 1 commit 2024-04-09 13:44:46 +02:00
29b8286fc8 Anim: use a non-allocating array inside CombinedKeyingResult
The data in CombinedKeyingResult was using BLI's Array type, which
heap allocates.  However, we know the array size at compile time,
and therefore can use std::array instead, as suggested in Array's
documentation.  This makes CombinedKeyingResult a lighter weight
plain-old-data class.
Nathan Vegdahl added the
Module
Animation & Rigging
label 2024-04-09 13:45:01 +02:00
Nathan Vegdahl requested review from Christoph Lendenfeld 2024-04-09 13:45:10 +02:00
Nathan Vegdahl requested review from Sybren A. Stüvel 2024-04-09 13:45:33 +02:00
Author
Member

This is a small enough change that I was considering just committing to main. But I decided to make it a PR for knowledge-sharing purposes.

This is a small enough change that I was considering just committing to main. But I decided to make it a PR for knowledge-sharing purposes.
Christoph Lendenfeld approved these changes 2024-04-09 15:15:56 +02:00
Christoph Lendenfeld left a comment
Member

looks good and still works as before

looks good and still works as before
Sybren A. Stüvel approved these changes 2024-04-09 16:40:33 +02:00
Sybren A. Stüvel left a comment
Member

👍 for knowledge sharing purposes. Otherwise I think this is a bit of a premature optimisation, where now the code is a bit harder to read. I doubt that this is going to practically speed up key insertion.

I'll leave it to you @nathanvegdahl to see if you still want to land ;-)

:+1: for knowledge sharing purposes. Otherwise I think this is a bit of a premature optimisation, where now the code is a bit harder to read. I doubt that this is going to practically speed up key insertion. I'll leave it to you @nathanvegdahl to see if you still want to land ;-)
Hans Goudey reviewed 2024-04-09 16:42:34 +02:00
@ -49,3 +50,3 @@
/* The index to the array maps a `SingleKeyingResult` to the number of times this result has
* occurred. */
Array<int> result_counter;
std::array<int, static_cast<size_t>(SingleKeyingResult::_KEYING_RESULT_MAX)> result_counter;
Member

The style guide mentions using functional style cast for this sort of cast: size_t(...

The style guide mentions using functional style cast for this sort of cast: `size_t(...`
nathanvegdahl marked this conversation as resolved
Nathan Vegdahl added 1 commit 2024-04-09 17:10:19 +02:00
Author
Member

@dr.sybren

Otherwise I think this is a bit of a premature optimisation

Yeah, that's fair. But for me it's less about optimization, and more that (IMO) if something can be POD, it almost always should be. Not for performance, but because POD types have trivial behavior/semantics, and are thus easier to reason about in code.

Additionally, Array's documentation specifically says to use std::array is these cases:

If the size is known at compile time, std::array<T, N> should be used instead.

@dr.sybren > Otherwise I think this is a bit of a premature optimisation Yeah, that's fair. But for me it's less about optimization, and more that (IMO) if something can be POD, it almost always should be. Not for performance, but because POD types have trivial behavior/semantics, and are thus easier to reason about in code. Additionally, `Array`'s documentation specifically says to use `std::array` is these cases: > If the size is known at compile time, `std::array<T, N>` should be used instead.
Nathan Vegdahl merged commit 05226881f7 into main 2024-04-09 17:27:29 +02:00
Nathan Vegdahl deleted branch combined_keying_result_no_alloc 2024-04-09 17:27:32 +02: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
4 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#120425
No description provided.