mirror of
https://github.com/YuzuZensai/TrollSSH.git
synced 2026-09-13 17:09:03 +00:00
🚀 perf: Performance and Memory optimization
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -8,3 +8,5 @@ func readFrameFile(filename string) (*frameFile, error) {
|
||||
data, err := os.ReadFile(filename)
|
||||
return &frameFile{data: data}, err
|
||||
}
|
||||
|
||||
func (f *frameFile) dropResident() {}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user