Skip to content

Commit 5a61323

Browse files
committed
Revert "perf: reduce memory usage + increase speed ~10%"
This reverts commit 2d8b7c7.
1 parent 2d8b7c7 commit 5a61323

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

pkg/demoinfocs/sendtables2/entity.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -437,25 +437,13 @@ func (e *Entity) readFields(r *reader, paths *[]*fieldPath) {
437437
val := decoder(r)
438438

439439
if base && (f.model == fieldModelVariableArray || f.model == fieldModelVariableTable) {
440-
fs := fieldState{}
440+
oldFS := e.state.get(fp)
441+
fs := newFieldState()
441442

442-
oldFS, ok := e.state.get(fp).(*fieldState)
443+
fs.state = make([]interface{}, val.(uint64))
443444

444-
if !ok {
445-
fs.state = make([]any, val.(uint64))
446-
}
447-
448-
if ok {
449-
if uint64(len(oldFS.state)) >= val.(uint64) {
450-
fs.state = oldFS.state[:val.(uint64)]
451-
} else {
452-
if uint64(cap(oldFS.state)) >= val.(uint64) {
453-
fs.state = oldFS.state[:val.(uint64)]
454-
} else {
455-
fs.state = make([]any, val.(uint64))
456-
copy(fs.state, oldFS.state)
457-
}
458-
}
445+
if oldFS != nil {
446+
copy(fs.state, oldFS.(*fieldState).state[:min(len(fs.state), len(oldFS.(*fieldState).state))])
459447
}
460448

461449
e.state.set(fp, fs)

pkg/demoinfocs/sendtables2/field_state.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package sendtables2
22

33
type fieldState struct {
4-
state []any
4+
state []interface{}
55
}
66

77
func newFieldState() *fieldState {
88
return &fieldState{
9-
state: make([]any, 8),
9+
state: make([]interface{}, 8),
1010
}
1111
}
1212

13-
func (s *fieldState) get(fp *fieldPath) any {
13+
func (s *fieldState) get(fp *fieldPath) interface{} {
1414
x := s
1515
z := 0
16-
1716
for i := 0; i <= fp.last; i++ {
1817
z = fp.path[i]
1918
if len(x.state) < z+1 {
@@ -27,21 +26,20 @@ func (s *fieldState) get(fp *fieldPath) any {
2726
}
2827
x = x.state[z].(*fieldState)
2928
}
30-
3129
return nil
3230
}
3331

34-
func (s *fieldState) set(fp *fieldPath, v any) {
32+
func (s *fieldState) set(fp *fieldPath, v interface{}) {
3533
x := s
3634
z := 0
3735

3836
for i := 0; i <= fp.last; i++ {
3937
z = fp.path[i]
4038

4139
if y := len(x.state); y <= z {
42-
newCap := max(z*2, y*2)
43-
if z+1 > cap(x.state) {
44-
newSlice := make([]any, z+1, newCap)
40+
newCap := max(z+2, y*2)
41+
if z+2 > cap(x.state) {
42+
newSlice := make([]interface{}, z+1, newCap)
4543
copy(newSlice, x.state)
4644
x.state = newSlice
4745
} else {

pkg/demoinfocs/sendtables2/serializer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ func (s *serializer) getFieldPathForName(fp *fieldPath, name string) bool {
8686

8787
func (s *serializer) getFieldPaths(fp *fieldPath, state *fieldState) []*fieldPath {
8888
results := make([]*fieldPath, 0, 4)
89-
9089
for i, f := range s.fields {
9190
fp.path[fp.last] = i
9291
results = append(results, f.getFieldPaths(fp, state)...)
9392
}
94-
9593
return results
9694
}
9795

0 commit comments

Comments
 (0)