Skip to content

Commit

Permalink
Merge pull request #16 from FindHotel/reduce-optional-allocations
Browse files Browse the repository at this point in the history
Reduce allocations and the footprint
  • Loading branch information
cswank authored Aug 19, 2021
2 parents 55e4ae2 + ec68c44 commit 7a7a3ff
Show file tree
Hide file tree
Showing 21 changed files with 698 additions and 535 deletions.
12 changes: 7 additions & 5 deletions cmd/bitpackgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,20 @@ var (
// Code generated by github.com/parsyl/parquet. DO NOT EDIT.
func Pack(width int, vals []uint8) []byte {
const MaxSize = {{.Max}}
func Pack(b []byte, width int, vals []uint8) []byte {
switch width {
{{range $i := N 1 .Max }}case {{$i}}:
return pack{{$i}}(vals)
return pack{{$i}}(b, vals)
{{end}}default:
return []byte{}
return b
}
}
{{range $i := N 1 .Max}}
func pack{{$i}}(vals []uint8) []byte {
return []byte{ {{template "bytes" $i}} }
func pack{{$i}}(b []byte, vals []uint8) []byte {
return append(b, {{template "bytes" $i}} )
}
{{end}}
Expand Down
11 changes: 7 additions & 4 deletions cmd/parquetgen/dremel/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func readOptional(f fields.Field) string {
n := f.MaxDef()
for def := 0; def < n; def++ {
out += fmt.Sprintf(`case x.%s == nil:
return nil, []uint8{%d}, nil
defs = append(defs, %d)
return vals, defs, reps
`, nilField(def, f), def)
}

Expand All @@ -29,13 +30,15 @@ func readOptional(f fields.Field) string {
}

out += fmt.Sprintf(` default:
return []%s{%sx.%s}, []uint8{%d}, nil`, cleanTypeName(f.Type), ptr, nilField(n, f), n)
vals = append(vals, %sx.%s)
defs = append(defs, %d)
return vals, defs, reps`, ptr, nilField(n, f), n)

return fmt.Sprintf(`func read%s(x %s) ([]%s, []uint8, []uint8) {
return fmt.Sprintf(`func read%s(x %s, vals []%s, defs, reps []uint8) ([]%s, []uint8, []uint8) {
switch {
%s
}
}`, strings.Join(f.FieldNames(), ""), f.StructType(), cleanTypeName(f.Type), out)
}`, strings.Join(f.FieldNames(), ""), f.StructType(), cleanTypeName(f.Type), cleanTypeName(f.Type), out)
}

func cleanTypeName(s string) string {
Expand Down
4 changes: 1 addition & 3 deletions cmd/parquetgen/dremel/read_repeated.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ type readClause struct {
}

func readRepeated(f fields.Field) string {
return fmt.Sprintf(`func read%s(x %s) ([]%s, []uint8, []uint8) {
var vals []%s
var defs, reps []uint8
return fmt.Sprintf(`func read%s(x %s, vals []%s, defs, reps []uint8) ([]%s, []uint8, []uint8) {
var lastRep uint8
%s
Expand Down
Loading

0 comments on commit 7a7a3ff

Please sign in to comment.