🚀 perf: Performance and Memory optimization

This commit is contained in:
2026-07-17 01:28:35 +07:00
parent facdb35d5d
commit 6d221846df
5 changed files with 100 additions and 21 deletions
+3
View File
@@ -112,6 +112,9 @@ func Load(filename string) (*FramesContainer, error) {
if off != len(raw) {
return nil, invalid()
}
file.dropResident()
data := &FramesContainer{ColorFrames: colorFrames, FPS: fps}
frameFileOwners.Store(data, file)
owned = true
+2
View File
@@ -8,3 +8,5 @@ func readFrameFile(filename string) (*frameFile, error) {
data, err := os.ReadFile(filename)
return &frameFile{data: data}, err
}
func (f *frameFile) dropResident() {}
+9
View File
@@ -28,6 +28,8 @@ func readFrameFile(filename string) (*frameFile, error) {
data, err := os.ReadFile(filename)
return &frameFile{data: data}, err
}
_ = syscall.Madvise(data, syscall.MADV_RANDOM)
return &frameFile{
data: data,
cleanup: func() error {
@@ -35,3 +37,10 @@ func readFrameFile(filename string) (*frameFile, error) {
},
}, nil
}
func (f *frameFile) dropResident() {
if f == nil || f.cleanup == nil || len(f.data) == 0 {
return
}
_ = syscall.Madvise(f.data, syscall.MADV_DONTNEED)
}