Hair particle distribution can be extremely slow #91568
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#91568
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: Quadro RTX 3000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 452.96
Blender Version
Broken: version: 2.93.4, branch: master, commit date: 2021-08-31 09:23, hash:
b7205031ce
Worked: ?
Short description of error
Depending on the mesh topology, the particule distribution can be extremely slow (render time varying from 9 seconds to 94 seconds for the same number of particles).
From my understanding while debugging the source code, most of the time is spent in particle distribution :
BLI_qsort_r
function called bypsys_thread_context_init_distribute
function.This is done in the section which states :
It seems that here,
BLI_qsort_r
hits the worst case O(n²) complexity case, which can happen depending on the input value distribution (see https:*research.swtch.com/qsort or http:*calmerthanyouare.org/2014/06/11/algorithmic-complexity-attacks-and-libc-qsort.html for more information)Exact steps for others to reproduce the error
Added subscriber: @rotoglup
Particle distribution can be extremely slowto Hair particle distribution can be extremely slowAdded subscribers: @Sergey, @iss
I can confirm this, though not sure how to classify, since I don't know the system well enough, hair system is marked as EOL and performance improvements are not considered bug. Disabling sorting does seem to have effect on final image so not sure what would be the solution to this problem even.
@Sergey I saw you involved in this area, do you think we should investigate possible improvements here?
If this is indeed an issue with worst-case complexity hit in the
BLI_qsort_r
this wouldn't be a hair system problem. Possible that the implementation of qsort we got from FreeBSD is susceptible to the problem.@rotoglup, while you're at it, did you try replacing
BLI_qsort_r
call with different qsort implementation?I'm far from being an expert in quicksort issues, or sorting algorithms, but my understanding is that it is the pivot selection strategy that can lead to worst-case scenarios.
I tried to change that strategy in the existing code (see attached diff) by changing the
med3
function, so that it modifies/sorts the values in place, before returning the median value.This removed the issue in my test scene, all tests seemed to pass - but - I'm not able to tell how it really impacts the worst-case scenarios.
I was inspired by this stackoveflow answer which says :
I also though that
timsort
could be a good alternative to quicksort, being stable and worst-case O(n log n) time complexity, or maybe particles, coming in very large numbers, could benefit from some custom sorting (radix sort maybe?)sort_pivot_swap_in_place.diff
Added subscriber: @mano-wii
Changed status from 'Needs Triage' to: 'Confirmed'
Revisiting some older reports, I found this one.
Generally, performance issues are not treated as bugs (especially involving particles that are in the "End of Life" state).
But a drop from 9 to 94 seconds in a situation where you would expect a faster render (since the subdivision modifier has been removed), seems to be something to keep track.
So I'm confirming it as a Bug for now.
I did a rudimentary test non threadsafe with
qsort
. The result was even worse: