Jelajahi Sumber

codec: changes for struct alignment

Ugorji Nwoke 6 tahun lalu
induk
melakukan
e6bc129461
3 mengubah file dengan 8 tambahan dan 5 penghapusan
  1. 5 3
      codec/decode.go
  2. 2 1
      codec/encode.go
  3. 1 1
      codec/helper.go

+ 5 - 3
codec/decode.go

@@ -24,8 +24,8 @@ const (
 const (
 	decDefMaxDepth         = 1024 // maximum depth
 	decDefSliceCap         = 8
-	decDefChanCap          = 64            // should be large, as cap cannot be expanded
-	decScratchByteArrayLen = cacheLineSize // - 5 // + (8 * 2) // - (8 * 1)
+	decDefChanCap          = 64                      // should be large, as cap cannot be expanded
+	decScratchByteArrayLen = cacheLineSize + (5 * 8) // - 5 // + (8 * 2) // - (8 * 1)
 
 	// decContainerLenUnknown is length returned from Read(Map|Array)Len
 	// when a format doesn't know apiori.
@@ -1372,7 +1372,9 @@ type Decoder struct {
 	calls uint16 // what depth in mustDecode are we in now.
 
 	c containerState
-	_ [1]byte                      // padding
+	_ [1]byte // padding
+
+	// ---- cpu cache line boundary?
 	b [decScratchByteArrayLen]byte // scratch buffer, used by Decoder and xxxDecDrivers
 
 	blist bytesFreelist

+ 2 - 1
codec/encode.go

@@ -862,11 +862,12 @@ type Encoder struct {
 	err error
 
 	// ---- cpu cache line boundary
+
 	// ---- writable fields during execution --- *try* to keep in sep cache line
 	ci set // holds set of addresses found during an encoding (if CheckCircularRef=true)
 	// cidef [1]interface{} // default ci
 
-	b [(5 * 8)]byte // for encoding chan byte, (non-addressable) [N]byte, etc
+	b [(7 * 8)]byte // for encoding chan byte, (non-addressable) [N]byte, etc
 
 	slist sfiRvFreelist
 	blist bytesFreelist

+ 1 - 1
codec/helper.go

@@ -114,7 +114,7 @@ import (
 )
 
 const (
-	scratchByteArrayLen = 32
+	scratchByteArrayLen = 64
 	// initCollectionCap   = 16 // 32 is defensive. 16 is preferred.
 
 	// Support encoding.(Binary|Text)(Unm|M)arshaler.