Add benchmark tests and optimize database performance
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled

- Introduced benchmark tests for various database operations, including event saving, querying, and fetching by serials, to assess performance.
- Implemented optimizations to reduce memory allocations and improve efficiency by pre-allocating slices and maps in critical functions.
- Enhanced the `FetchEventsBySerials`, `GetFullIdPubkeyBySerials`, and `QueryForIds` methods with pre-allocation strategies to minimize reallocations.
- Documented performance improvements in the new PERFORMANCE_REPORT.md file, highlighting significant reductions in execution time and memory usage.
- Bumped version to v0.23.1 to reflect these changes.
This commit is contained in:
2025-11-02 18:19:52 +00:00
parent d7ea462642
commit 8d131b6137
10 changed files with 513 additions and 25 deletions

View File

@@ -32,6 +32,8 @@ func (d *D) QueryForIds(c context.Context, f *filter.F) (
}
var results []*store.IdPkTs
var founds []*types.Uint40
// Pre-allocate results slice with estimated capacity to reduce reallocations
results = make([]*store.IdPkTs, 0, len(idxs)*100) // Estimate 100 results per index
// When searching, we want to count how many index ranges (search terms)
// matched each note. We'll track counts by serial.
counts := make(map[uint64]int)
@@ -53,7 +55,8 @@ func (d *D) QueryForIds(c context.Context, f *filter.F) (
}
// deduplicate in case this somehow happened (such as two or more
// from one tag matched, only need it once)
seen := make(map[uint64]struct{})
seen := make(map[uint64]struct{}, len(results))
idPkTs = make([]*store.IdPkTs, 0, len(results))
for _, idpk := range results {
if _, ok := seen[idpk.Ser]; !ok {
seen[idpk.Ser] = struct{}{}