From c4f1d519ed7d816dd52303942b3e73a8e6f8e577 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 26 Nov 2022 00:34:25 -0500 Subject: [PATCH] Use int8 for mvtype (memory reduction) (#1130) * Use int8 for mvtype (memory reduction) * Try to get around codespell false positives --- .github/workflows/codespell.yml | 2 +- cmd/sizes/main.go | 19 +++++++++++++++++++ internal/pkg/mlrval/mlrval_output.go | 17 +++++++++++++++++ internal/pkg/mlrval/mlrval_type.go | 13 ++++++------- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 cmd/sizes/main.go diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 60daa5045..497335281 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -33,4 +33,4 @@ jobs: with: check_filenames: true ignore_words_file: .codespellignore - skip: "*.csv,*.dkvp,*.txt,*.js,*.html,*.map,./tags,./test/cases,./docs/src/shapes-of-data.md.in,./docs/src/shapes-of-data.md" + skip: "*.csv,*.dkvp,*.txt,*.js,*.html,*.map,*.z,./tags,./test/cases,./docs/src/shapes-of-data.md.in,./docs/src/shapes-of-data.md,test/input/latin1.xtab" diff --git a/cmd/sizes/main.go b/cmd/sizes/main.go new file mode 100644 index 000000000..bddb09082 --- /dev/null +++ b/cmd/sizes/main.go @@ -0,0 +1,19 @@ +// ================================================================ +// Experiments for type-inference performance optimization +// ================================================================ + +// go build github.com/johnkerl/miller/cmd/sizes + +package main + +import ( + "github.com/johnkerl/miller/internal/pkg/mlrval" +) + +func main() { + var mvs [2]mlrval.Mlrval + mvs[0] = *mlrval.FromString("hello") + mvs[1] = *mlrval.FromString("world") + mvs[0].ShowSizes() + mvs[1].ShowSizes() +} diff --git a/internal/pkg/mlrval/mlrval_output.go b/internal/pkg/mlrval/mlrval_output.go index 56912e5d9..4d6757340 100644 --- a/internal/pkg/mlrval/mlrval_output.go +++ b/internal/pkg/mlrval/mlrval_output.go @@ -3,6 +3,7 @@ package mlrval import ( "fmt" "os" + "reflect" "strconv" ) @@ -122,3 +123,19 @@ func (mv *Mlrval) StringifyValuesRecursively() { mv.SetFromString(mv.String()) } } + +func (mv *Mlrval) ShowSizes() { + fmt.Printf("TOTAL %p %d\n", mv, reflect.TypeOf(*mv).Size()) + fmt.Printf("mv.intval %p %d\n", &mv.intval, reflect.TypeOf(mv.intval).Size()) + fmt.Printf("mv.floatval %p %d\n", &mv.floatval, reflect.TypeOf(mv.floatval).Size()) + fmt.Printf("mv.printrep %p %d\n", &mv.printrep, reflect.TypeOf(mv.printrep).Size()) + fmt.Printf("mv.printrepValid %p %d\n", &mv.printrepValid, reflect.TypeOf(mv.printrepValid).Size()) + fmt.Printf("mv.boolval %p %d\n", &mv.boolval, reflect.TypeOf(mv.boolval).Size()) + fmt.Printf("mv.mvtype %p %d\n", &mv.mvtype, reflect.TypeOf(mv.mvtype).Size()) + + fmt.Printf("mv.arrayval %p %d\n", &mv.arrayval, reflect.TypeOf(mv.arrayval).Size()) + fmt.Printf("mv.mapval %p %d\n", &mv.mapval, reflect.TypeOf(mv.mapval).Size()) + if mv.funcval != nil { + fmt.Printf("mv.funcval %p %d\n", &mv.funcval, reflect.TypeOf(mv.funcval).Size()) + } +} diff --git a/internal/pkg/mlrval/mlrval_type.go b/internal/pkg/mlrval/mlrval_type.go index 9e38ead8f..a752360a0 100644 --- a/internal/pkg/mlrval/mlrval_type.go +++ b/internal/pkg/mlrval/mlrval_type.go @@ -54,17 +54,16 @@ package mlrval type Mlrval struct { + intval int64 + floatval float64 + printrep string + printrepValid bool + boolval bool // Enumeration for string / int / float / boolean / etc. // I would call this "type" not "mvtype" but "type" is a keyword in Go. mvtype MVType - printrep string - printrepValid bool - intval int64 - floatval float64 - boolval bool - arrayval []*Mlrval mapval *Mlrmap // First-class-function literals from internal/pkg/dsl/cst. @@ -84,7 +83,7 @@ const ABSENT_PRINTREP = "(absent)" // JavaScript, similarly, there are undefined and null, respectively -- // Miller's absent is more like JavaScript's undefined.) -type MVType int +type MVType int8 // Important: the values of these enums are used to index into disposition // matrices. If they are changed, it will break the disposition matrices, or