Skip to content

performance (XLStyle): Custom GetHashCode to improve performance on XLStyle structs #2677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jafin
Copy link

@jafin jafin commented May 4, 2025

Summary

Custom GetHashCode to improve performance on XLStyle structs Slight reduction in memory allocation. vs using HashCode()

Benchmarks

NOTE: These benchmarks are from when I stacked this PR ontop of #2674 and execute the benchmark test in that PR, but it does illustrate the change.

Before

Method Mean Error StdDev Gen0 Gen1 Allocated
CellFillAndCopy 43.96 ms 0.875 ms 0.899 ms 1700.0000 800.0000 28.17 MB

After GetHashCode Changes.

Method Mean Error StdDev Gen0 Gen1 Allocated
CellFillAndCopy 41.08 ms 0.818 ms 1.475 ms 1692.3077 615.3846 27.99 MB

Why HashCode may be slower

It has extra state and indirection
HashCode is a mutable struct that maintains internal buffers
Each .Add() writes into the buffer
When calling .ToHashCode() → it combines state + random salt → extra CPU cost

…LStyle. structs. Slight reduction in memory allocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant