From c6c87b3d1fbb3fd8a8eee1b4bb55be2b6e53d5d3 Mon Sep 17 00:00:00 2001 From: esimov Date: Thu, 24 Nov 2022 11:13:59 +0200 Subject: [PATCH] perf: struct memory alignment --- cmd/pigo/main.go | 15 ++++++--------- core/pigo.go | 10 +++++----- core/puploc.go | 10 +++++----- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/pigo/main.go b/cmd/pigo/main.go index f4999f5..a8962a7 100644 --- a/cmd/pigo/main.go +++ b/cmd/pigo/main.go @@ -35,9 +35,6 @@ Go (Golang) Face detection library. ` -// messageType is a placeholder for various message types. -type messageType int - // pipeName is the file name that indicates stdin/stdout is being used. const pipeName = "-" @@ -69,22 +66,22 @@ var ( ) var ( - eyeCascades = []string{"lp46", "lp44", "lp42", "lp38", "lp312"} - mouthCascades = []string{"lp93", "lp84", "lp82", "lp81"} + eyeCascades = [5]string{"lp46", "lp44", "lp42", "lp38", "lp312"} + mouthCascades = [4]string{"lp93", "lp84", "lp82", "lp81"} ) // faceDetector struct contains Pigo face detector general settings. type faceDetector struct { - angle float64 cascadeFile string destination string + puploc string + flploc string + angle float64 minSize int maxSize int shiftFactor float64 scaleFactor float64 iouThreshold float64 - puploc string - flploc string markDetEyes bool } @@ -97,9 +94,9 @@ type coord struct { // detection holds the detection points of the various detection types type detection struct { - FacePoints coord `json:"face,omitempty"` EyePoints []coord `json:"eyes,omitempty"` LandmarkPoints []coord `json:"landmark_points,omitempty"` + FacePoints coord `json:"face,omitempty"` } func main() { diff --git a/core/pigo.go b/core/pigo.go index ad6bdd2..4eec8cf 100644 --- a/core/pigo.go +++ b/core/pigo.go @@ -14,11 +14,11 @@ import ( // ShiftFactor: determines to what percentage to move the detection window over its size. // ScaleFactor: defines in percentage the resize value of the detection window when moving to a higher scale. type CascadeParams struct { + ImageParams MinSize int MaxSize int ShiftFactor float64 ScaleFactor float64 - ImageParams } // ImageParams is a struct for image related settings. @@ -35,11 +35,11 @@ type ImageParams struct { // Pigo struct defines the basic binary tree components. type Pigo struct { - treeDepth uint32 - treeNum uint32 treeCodes []int8 treePred []float32 treeThreshold []float32 + treeDepth uint32 + treeNum uint32 } // NewPigo initializes the Pigo constructor method. @@ -101,11 +101,11 @@ func (pg *Pigo) Unpack(packet []byte) (*Pigo, error) { } return &Pigo{ - treeDepth, - treeNum, treeCodes, treePred, treeThreshold, + treeDepth, + treeNum, }, nil } diff --git a/core/puploc.go b/core/puploc.go index d49d31a..b58c42d 100644 --- a/core/puploc.go +++ b/core/puploc.go @@ -21,12 +21,12 @@ type Puploc struct { // PuplocCascade is a general struct for storing // the cascade tree values encoded into the binary file. type PuplocCascade struct { - stages uint32 - scales float32 - trees uint32 - treeDepth uint32 treeCodes []int8 treePreds []float32 + scales float32 + stages uint32 + trees uint32 + treeDepth uint32 } // NewPuplocCascade initializes the PuplocCascade constructor method. @@ -237,7 +237,7 @@ var plcPool = sync.Pool{ // RunDetector runs the pupil localization function. func (plc *PuplocCascade) RunDetector(pl Puploc, img ImageParams, angle float64, flipV bool) *Puploc { - var res = make([]float32, 3) + var res []float32 det := plcPool.Get().(*puplocPool) defer plcPool.Put(det)