quintodrome/model/metadata
Deluan Quintão ab2f1b45de
perf: reduce hot-path heap escapes from value-param pointer aliasing (#5342)
* perf(subsonic): keep album/mediafile params on stack in response helpers

Two helpers were forcing their entire value parameter onto the heap via
pointer-to-field aliasing, adding one full-struct heap allocation per
response item on hot Subsonic endpoints (search3, getAlbumList2, etc.).

- childFromMediaFile assigned &mf.BirthTime to the returned Child,
  pulling the whole ~1KB model.MediaFile to the heap on every call.
- buildDiscSubtitles passed &a.UpdatedAt to NewArtworkID inside a loop,
  pulling the whole model.Album to the heap on every album with discs.

Both now copy the time.Time to a stack-local and use gg.P / &local so
only the small time.Time escapes. Verified via go build -gcflags=-m=2:
moved to heap: mf and moved to heap: a are gone at these sites.

* perf(metadata): avoid per-track closure allocations in PID computation

createGetPID was a factory that returned nested closures capturing
mf model.MediaFile (~992 bytes) by reference. Since it is called three
times per track during scans (trackPID, albumID, artistID), every track
triggered the allocation of three closures plus a heap copy of the full
MediaFile.

Refactor the body into package-level functions (computePID, getPIDAttr)
that take hash as an explicit parameter and the inner slice.Map callback
to an indexed for loop, removing the closure-capture of mf entirely.
trackPID/albumID/artistID now call computePID directly.

The tiny createGetPID wrapper was kept only for tests; move the
closure-building into the test file so production has no dead API.

Verified via go build -gcflags=-m=2 on model/metadata: no
"moved to heap: mf" anywhere in persistent_ids.go, and the callers in
map_mediafile.go / map_participants.go no longer heap-promote their
MediaFile argument.
2026-04-10 21:59:49 -04:00
..
legacy_ids.go refactor(scanner): refactor legacyReleaseDate logic and add tests for date mapping 2025-11-12 13:11:33 -05:00
map_mediafile.go feat(subsonic): implement OpenSubsonic Transcoding extension (#4990) 2026-03-08 23:57:49 -04:00
map_mediafile_test.go refactor(scanner): refactor legacyReleaseDate logic and add tests for date mapping 2025-11-12 13:11:33 -05:00
map_participants.go feat(server): custom ArtistJoiner config (#3873) 2025-03-23 10:53:21 -04:00
map_participants_test.go test: add PERFORMER tests (#4105) 2025-05-22 16:41:08 -04:00
metadata.go feat(subsonic): implement OpenSubsonic Transcoding extension (#4990) 2026-03-08 23:57:49 -04:00
metadata_suite_test.go feat(bfr): Big Refactor: new scanner, lots of new fields and tags, improvements and DB schema changes (#2709) 2025-02-19 20:35:17 -05:00
metadata_test.go fix(scanner): preserve parentheses in lyrics when processing alias tags (#4985) 2026-02-06 16:21:35 -05:00
persistent_ids.go perf: reduce hot-path heap escapes from value-param pointer aliasing (#5342) 2026-04-10 21:59:49 -04:00
persistent_ids_test.go perf: reduce hot-path heap escapes from value-param pointer aliasing (#5342) 2026-04-10 21:59:49 -04:00