mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
perf(tracker): use json recovery files instead of yaml for less garbage
The yaml marshaling and umarshaling seems to allocate a lot of memory. When saving the recovery file, the memory use jumped up by hundreds of megabytes. Switch to using json marshaling for the recovery file, as it does waste memory so badly. Binary marshaling was also an option, but its nice in emergency situations that the user can glance the recovery file and perhaps, with some effort, recover stuff from it. Json is good enough for manual recovery during emergency situations.
This commit is contained in:
parent
4899b027ff
commit
97a1b2f766
@ -1,6 +1,7 @@
|
||||
package tracker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
"github.com/vsariola/sointu"
|
||||
"github.com/vsariola/sointu/vm"
|
||||
"golang.org/x/exp/slices"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Model implements the mutable state for the tracker program GUI.
|
||||
@ -113,7 +114,7 @@ const (
|
||||
)
|
||||
|
||||
const maxUndo = 64
|
||||
const RECOVERY_FILE = ".sointu_recovery.yml"
|
||||
const RECOVERY_FILE = ".sointu_recovery"
|
||||
|
||||
func NewModel(modelMessages chan<- interface{}, playerMessages <-chan PlayerMessage) *Model {
|
||||
ret := new(Model)
|
||||
@ -135,10 +136,14 @@ func LoadRecovery(modelMessages chan<- interface{}, playerMessages <-chan Player
|
||||
return nil, fmt.Errorf("could not read recovery file: %w", err)
|
||||
}
|
||||
var ret Model
|
||||
err = yaml.Unmarshal(b, &ret.d)
|
||||
err = json.Unmarshal(b, &ret.d)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal recovery file: %w", err)
|
||||
err = yaml.Unmarshal(b, &ret.d)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal recovery file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
ret.modelMessages = modelMessages
|
||||
ret.PlayerMessages = playerMessages
|
||||
ret.notifyPatchChange()
|
||||
@ -152,7 +157,7 @@ func (m *Model) SaveRecovery() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get user home directory: %w", err)
|
||||
}
|
||||
out, err := yaml.Marshal(m.d)
|
||||
out, err := json.Marshal(m.d)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not marshal the model: %w", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user