Skip to content

Commit

Permalink
lhef: reduce allocs on event decoding
Browse files Browse the repository at this point in the history
When decoding an event block, allocate memory for slices in bigger
blocks to reduce the number of memory allocations.
  • Loading branch information
dolmen authored and sbinet committed May 10, 2022
1 parent 9c5c566 commit 1992369
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lhef/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ func (d *Decoder) Decode() (*HEPEUP, error) {
n := int(evt.NUP)
evt.IDUP = make([]int64, n)
evt.ISTUP = make([]int32, n)
evt.MOTHUP = make([][2]int32, n)
evt.ICOLUP = make([][2]int32, n)
n2 := make([][2]int32, 2*n)
evt.MOTHUP = n2[:n:n]
evt.ICOLUP = n2[n:]
evt.PUP = make([][5]float64, n)
evt.VTIMUP = make([]float64, n)
evt.SPINUP = make([]float64, n)
f64 := make([]float64, 2*n)
evt.VTIMUP = f64[:n:n]
evt.SPINUP = f64[n:]
for i := 0; i < n; i++ {
_, err = fmt.Fscanf(
buf,
Expand Down

0 comments on commit 1992369

Please sign in to comment.