]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/internal/goobj2: optimize symbol data access
authorCherry Zhang <cherryyz@google.com>
Fri, 6 Mar 2020 17:36:58 +0000 (12:36 -0500)
committerCherry Zhang <cherryyz@google.com>
Mon, 16 Mar 2020 17:33:24 +0000 (17:33 +0000)
I wish the compiler inlines the DataOff function and CSEs the
base offset calculation. But it didn't happen. Hand optimize it...

(linking cmd/compile)
Dostkcheck    42.0ms ± 0%    36.1ms ± 2%  -14.07%  (p=0.008 n=5+5)

Change-Id: Iacfbc7243a882158a9a090b7400e216536a311b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/222304
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/internal/goobj2/objfile.go

index d5a9b4aa8cd193c340ebc8667e7be0c7db70d9f4..d93c28afff6fc236de7c4afe35e7bb7311cdb2d2 100644 (file)
@@ -617,12 +617,17 @@ func (r *Reader) DataOff(i int) uint32 {
 
 // DataSize returns the size of the i-th symbol's data.
 func (r *Reader) DataSize(i int) int {
-       return int(r.DataOff(i+1) - r.DataOff(i))
+       dataIdxOff := r.h.Offsets[BlkDataIdx] + uint32(i*4)
+       return int(r.uint32At(dataIdxOff+4) - r.uint32At(dataIdxOff))
 }
 
 // Data returns the i-th symbol's data.
 func (r *Reader) Data(i int) []byte {
-       return r.BytesAt(r.DataOff(i), r.DataSize(i))
+       dataIdxOff := r.h.Offsets[BlkDataIdx] + uint32(i*4)
+       base := r.h.Offsets[BlkData]
+       off := r.uint32At(dataIdxOff)
+       end := r.uint32At(dataIdxOff + 4)
+       return r.BytesAt(base+off, int(end-off))
 }
 
 // AuxDataBase returns the base offset of the aux data block.