HangfireIO / HangfireIO/Hangfire
InsertToList() performance
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
Version: 1.8.10
Storage: Hangfire.SqlServer
ConfigurationLogic: any
Custom Filters: none
Description:
When inserting to a list, an exclusive lock is taken on all existing rows with the same key by means of selecting them:
https://github.com/HangfireIO/Hangfire/blob/d1f9bbe9be8f1b0028b607a94608703b6cd88e54/src/Hangfire.SqlServer/SqlServerWriteOnlyTransaction.cs#L367
I was a bit confused about why this happens - as a shared application lock has already been taken on the key before this Sql statement runs...
The reason I ask is that when the list for a give key becomes long, all the previous rows are selected, meaning an insert at position 1 million requires selecting the previous 999,999 rows - and that doesn't perform well..
Contributor guide
Research direction
Start at src/Hangfire.SqlServer/SqlServerWriteOnlyTransaction.cs around line 367 and inspect how InsertToList() selects rows for the same key. Reproduce or measure the behavior with a long list if the repository provides a relevant test or benchmark. Done means establishing whether the existing row selection is necessary and documenting or addressing the reported performance cost.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100