BLI: avoid compiling same function multiple times for trivial types #119601

Merged
Jacques Lucke merged 4 commits from JacquesLucke/blender:reduce-cpp-types-code-gen into main 2024-03-19 13:45:14 +01:00
Member

For example, copying and moving a trivial type ends is the same. However, currently we generate the code for both cases independently instead of reusing the same underlying function.

This reduces the size of the Blender binary from 218.548.896 to 218.355.552 bytes for me. So it's a reduction of about 200kb.

It's probably possible to reduce this even more, but that's for another day. The main tricky thing here is telling the compiler that a const from a function parameter can be cast away for trivial types (see code comment). Maybe there is a better way to do this while making sure the compiler doesn't generate unnecessary code.

For example, copying and moving a trivial type ends is the same. However, currently we generate the code for both cases independently instead of reusing the same underlying function. This reduces the size of the Blender binary from `218.548.896` to `218.355.552` bytes for me. So it's a reduction of about 200kb. It's probably possible to reduce this even more, but that's for another day. The main tricky thing here is telling the compiler that a `const` from a function parameter can be cast away for trivial types (see code comment). Maybe there is a better way to do this while making sure the compiler doesn't generate unnecessary code.
Jacques Lucke added 1 commit 2024-03-17 21:26:27 +01:00
Jacques Lucke added 1 commit 2024-03-17 21:28:28 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 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-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
92d68a389b
improve comment
Jacques Lucke requested review from Hans Goudey 2024-03-17 21:33:47 +01:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey approved these changes 2024-03-18 20:14:55 +01:00
Hans Goudey left a comment
Member

Nice change! I can confirm the binary size reduction. And if anything there would be a performance improvement too, from better cache use!

Nice change! I can confirm the binary size reduction. And if anything there would be a performance improvement too, from better cache use!
@ -252,2 +259,2 @@
move_assign_ = move_assign_cb<T>;
move_assign_indices_ = move_assign_indices_cb<T>;
if constexpr (std::is_trivially_move_assignable_v<T>) {
/* This casts away the const from the src pointer. This should be fine for trivial types as
Member

How about should be -> is so reading the code doesn't leave me with a sense of doubt? :)

How about `should be` -> `is` so reading the code doesn't leave me with a sense of doubt? :)
JacquesLucke marked this conversation as resolved
Jacques Lucke added 2 commits 2024-03-19 13:43:51 +01:00
Jacques Lucke merged commit dc762d0914 into main 2024-03-19 13:45:14 +01:00
Jacques Lucke deleted branch reduce-cpp-types-code-gen 2024-03-19 13:45:17 +01: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 project
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#119601
No description provided.