Libraries: integrate xxHash library for fast hashing #120139

Merged
Jacques Lucke merged 5 commits from JacquesLucke/blender:xxhash into main 2024-04-03 10:23:04 +02:00
Member

xxHash is a fast non-cryptographic hashing library. It significantly outperforms md5 which we use in some places currently while also having great collision resistance if not attacked explicitly.

The library is added to extern because that was the easiest way to do it and has the least impact on others. I expect this library to become a required dependency instead of an optional one. It's licence is BSD 2-Clause which seems to be the first of its kind in Blender (there is BSD 3-Clause a couple of times). From what I can tell, this licence is compatible with ours.

For now, I used the library only for data deduplication when baking geometry nodes. The time to bake the setup below goes down from >6s to <1s (note that this includes more than just the hashing time).

image

[xxHash](https://xxhash.com/) is a fast non-cryptographic hashing library. It significantly outperforms md5 which we use in some places currently while also having great [collision resistance](https://github.com/Cyan4973/xxHash/tree/dev/tests/collisions) if not attacked explicitly. The library is added to `extern` because that was the easiest way to do it and has the least impact on others. I expect this library to become a required dependency instead of an optional one. It's licence is `BSD 2-Clause` which seems to be the first of its kind in Blender (there is `BSD 3-Clause` a couple of times). From what I can tell, this licence is compatible with ours. For now, I used the library only for data deduplication when baking geometry nodes. The time to bake the setup below goes down from >6s to <1s (note that this includes more than just the hashing time). ![image](/attachments/71003c96-8c83-4bb0-9948-25b175883633)
Jacques Lucke added 1 commit 2024-04-01 11:51:16 +02:00
Jacques Lucke added 1 commit 2024-04-01 12:00:38 +02: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
5e11b04994
use XXH3_64bits
Author
Member

@blender-bot build

@blender-bot build
Jacques Lucke requested review from Brecht Van Lommel 2024-04-01 12:26:58 +02:00
Jacques Lucke requested review from Ray molenkamp 2024-04-01 12:26:59 +02:00
Jacques Lucke requested review from Hans Goudey 2024-04-01 12:26:59 +02:00
Jacques Lucke requested review from Aras Pranckevicius 2024-04-01 12:26:59 +02:00
Aras Pranckevicius reviewed 2024-04-01 16:22:16 +02:00
@ -0,0 +1,6 @@
Project: xxHash
URL: https://xxhash.com/
License: BSD 2-Clause
Upstream version: 2024-04-01

Minor: for me it's clearer if version also indicates the commit and/or release version. Like with 2024-04-01 it's not clear whether it is d28b0bf from dev branch (2024-03-24) or bbb27a5 from release branch (2023-07-21, also shipped as version v0.8.2)

Minor: for me it's clearer if version also indicates the commit and/or release version. Like with 2024-04-01 it's not clear whether it is `d28b0bf` from dev branch (2024-03-24) or `bbb27a5` from release branch (2023-07-21, also shipped as version v0.8.2)
JacquesLucke marked this conversation as resolved
Aras Pranckevicius approved these changes 2024-04-01 16:24:19 +02:00
Dismissed
Aras Pranckevicius left a comment
Member

Nice! One minor comment wrt which version exactly is used from upstream.

Would be good for someone to look at some point whether this could be used in some other places where today some slow(er) hash functions are used.

Nice! One minor comment wrt which version exactly is used from upstream. Would be good for someone to look at some point whether this could be used in some other places where today some slow(er) hash functions are used.
Ray molenkamp approved these changes 2024-04-01 17:08:09 +02:00
Ray molenkamp left a comment
Member

I agree with @aras_p here, please provide either the exact version or hash you used, also gitea doesn't have a blocking reviewer concept but @brecht or someone else from core/admin has to accept this before landing, do not land without this.

also cc: @ThomasDinges as he maintains the compliance documentation.

I agree with @aras_p here, please provide either the exact version or hash you used, also gitea doesn't have a blocking reviewer concept but @brecht or someone else from core/admin _has_ to accept this before landing, do not land without this. also cc: @ThomasDinges as he maintains the compliance documentation.
Jacques Lucke added 1 commit 2024-04-01 18:07:50 +02: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
762c3b04aa
use latest xxhash release (0.8.2) instead of dev branch
Author
Member

Would be good for someone to look at some point whether this could be used in some other places where today some slow(er) hash functions are used.

I think this could at least replace all of our usages of md5 which we could potentially also remove. It might also replace our usages of murmur hash, but that needs to be checked in more detail.

> Would be good for someone to look at some point whether this could be used in some other places where today some slow(er) hash functions are used. I think this could at least replace all of our usages of `md5` which we could potentially also remove. It might also replace our usages of murmur hash, but that needs to be checked in more detail.
Author
Member

@blender-bot build

@blender-bot build

I think this could at least replace all of our usages of md5 which we could potentially also remove. It might also replace our usages of murmur hash, but that needs to be checked in more detail.

Hardest part is usually knowing whether "something" depends on exact hash values not changing, ever. Like if the hashes are used to generate some number identifiers that are then saved into files, etc. If it is strictly just runtime hashtables or some serialized caches that by design can be "regenerated", it is easier -- but you have to look and determine if that is the case or not.

Last time I did hash performance comparisons was 8 years ago, back then xxHash (before XXH3 existed) was generally faster than murmur hash family, including for very small data. So I suspect XXH3 might be even better, considering that one of the "things" about XXH3 is how it is faster to compute for small data sizes.

I suspect hash_string might also be a candidate for replacement, but probably needs to get evaluated what are the usual string lengths that it is called on. For very short strings the current inline function might be better, even if it hashes one byte at a time.

> I think this could at least replace all of our usages of `md5` which we could potentially also remove. It might also replace our usages of murmur hash, but that needs to be checked in more detail. Hardest part is usually knowing whether "something" depends on exact hash values not changing, ever. Like if the hashes are used to generate some number identifiers that are then saved into files, etc. If it is strictly just runtime hashtables or some serialized caches that by design can be "regenerated", it is easier -- but you have to look and determine if that is the case or not. Last time I did [hash performance comparisons](https://aras-p.info/blog/2016/08/09/More-Hash-Function-Tests/) was 8 years ago, back then xxHash (before XXH3 existed) was generally faster than murmur hash family, including for very small data. So I suspect XXH3 might be even better, considering that one of the "things" about XXH3 is how it is faster to compute for small data sizes. I suspect `hash_string` might also be a candidate for replacement, but probably needs to get evaluated what are the usual string lengths that it is called on. For *very* short strings the current inline function might be better, even if it hashes one byte at a time.
Aras Pranckevicius approved these changes 2024-04-02 08:31:58 +02:00
Hans Goudey approved these changes 2024-04-02 13:56:33 +02:00
Jacques Lucke requested review from Thomas Dinges 2024-04-02 16:19:52 +02:00
Jacques Lucke requested review from Sergey Sharybin 2024-04-02 16:20:16 +02:00

I think its fine to have this library. Having it in extern also minimizes an impact on people who do not use precompiled libraries.

To be fully ready the remaining part is to add release/license/BSD-2-Clause.txt.

I think its fine to have this library. Having it in `extern` also minimizes an impact on people who do not use precompiled libraries. To be fully ready the remaining part is to add `release/license/BSD-2-Clause.txt`.
Jacques Lucke added 2 commits 2024-04-03 10:05:30 +02:00
Sergey Sharybin approved these changes 2024-04-03 10:14:56 +02:00
Jacques Lucke merged commit e2d170f685 into main 2024-04-03 10:23:04 +02:00
Jacques Lucke deleted branch xxhash 2024-04-03 10:23:07 +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
5 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#120139
No description provided.