GHash Improvements #43766
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
FBX
Interest
Freestyle
Interest
Geometry Nodes
Interest
glTF
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#43766
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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?
This task is related to work done on our GHash in temp-ghash-experiments branch.
Current Branch vs Master
This is a simple comparison between new code in branch and master one, using as close a possible same tests. Both are done using modulo, and no pre-reservation of buckets. Master uses load 3.0, new branch, load 0.75. New branch also adds hash stored in entries.
Notes:
no hash
in table above) gives nearly no speedup.Reducing Load
Here are the results of some tests, ran using this corpus (1 million of words, about 122MB of text), from corpora.informatik.uni-leipzig.de.
Inserted keys were: the whole text, all its lines, and all its words, leading to 2 917 605 entries.
Notes:
From that we can conclude (at least for now) that:
Also, we can see how important it is to pre-allocate (reserve) GHash buckets whenever possible. Resizing buckets is a very expansive operation. We can also see how interesting it can be to over-reserve buckets for better lookup times (see differences in lookup times between different % of load).
Storing Hashes
And now, here are some results with hashes stored in entries:
Benefits are obvious, non-reserved times are now quite close to reserve times even!
When Using Non-hashing Hash Functions
Yes, we do that in Blender - quit a bit actually!
Here we store 20M entries using raw pointers addresses as keys (from an array, so keys are consecutive addresses). No surprise here, a single modulo division shines, because (due to load < 1) it can perfectly spread all entries, while masking (since addresses are not small values) fails quite heavily. Note that even in this hyper-worst-case scenario, performances of masking are not that catastrophic.
In any other tested cases (consecutive ints starting from zero, and random ints), masking and modulo get very similar results.
So I think either we decide to stick to modulo, accepting the (more or less) 10% loss of speed, or we decide to switch to masking, which involves a careful check of all cases where we are currently using raw integers as hashes (e.g.
ghashutil_bmelem_indexhash()
,imagecache_hashhash()
, …). First solution looks simpler for now.About memory
Here are some (rough) estimations for 100M of entries:
In other words, all proposed changes approximately increase the memory footprint of GHash of 60%, and of GSet of 86%.
But our typical usage in Blender nearly never involves more than a few millions entries (usually much less actually), so I would not consider that an issue?
Changed status to: 'Open'
Added subscribers: @mont29, @ideasman42
Next things to check:
Added hashes to entries, this gives another nice boost in resizing, but also lookup (due to the fact comparing the hash avoids us many comparison on actual key value, which can be expansive e.g. with strings, I guess).
Also tried to increment sizes by two (instead of one) for small ones (below 16), but this did not showed any benefit when inserting into a non-reserved ghash, times were actually even worse (not sure why).
Changed status from 'Open' to: 'Archived'