Skip to content

Commit 6ba8681

Browse files
authored
updates (#74)
- Updating GitHub Actions. - Added declaration of MSGV(Minimum Supported Go Version) - Optimized map cleanup using `clear` introduced in Go v1.21 Notes on MSGV will be being. See prior discussion [here](go-playground/validator#1342) for more details in one of my other repos.
1 parent cd3bad6 commit 6ba8681

File tree

7 files changed

+56
-34
lines changed

7 files changed

+56
-34
lines changed

.github/workflows/workflow.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ jobs:
88
test:
99
strategy:
1010
matrix:
11-
go-version: [1.17.x, 1.20.x]
11+
go-version: [1.24.x, 1.25.x]
1212
os: [ubuntu-latest, macos-latest, windows-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- name: Install Go
16-
uses: actions/setup-go@v3
16+
uses: actions/setup-go@v5
1717
with:
1818
go-version: ${{ matrix.go-version }}
1919

2020
- name: Checkout code
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Restore Cache
24-
uses: actions/cache@v3
24+
uses: actions/cache@v4
2525
with:
2626
path: ~/go/pkg/mod
2727
key: ${{ runner.os }}-v1-go-${{ hashFiles('**/go.sum') }}
@@ -41,7 +41,7 @@ jobs:
4141
name: lint
4242
runs-on: ubuntu-latest
4343
steps:
44-
- uses: actions/checkout@v3
44+
- uses: actions/checkout@v5
4545
- name: golangci-lint
4646
uses: golangci/golangci-lint-action@v3
4747
with:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test:
77
go test -covermode=atomic -race ./...
88

99
bench:
10-
go test -bench=. -benchmem ./...
10+
go test -run=NONE -bench=. -benchmem ./...
1111

1212
.PHONY: test lint bench
1313
.DEFAULT_GOAL := all

README.md

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -282,34 +282,56 @@ Benchmarks
282282
NOTE: the 1 allocation and B/op in the first 4 decodes is actually the struct allocating when passing it in, so primitives are actually zero allocation.
283283

284284
```go
285-
go test -run=NONE -bench=. -benchmem=true ./...
285+
go test -run=NONE -bench=. -benchmem ./...
286+
goos: darwin
287+
goarch: arm64
288+
pkg: github.com/go-playground/form/v4
289+
cpu: Apple M3 Max
290+
BenchmarkNestedArrayDecode100-16 75 15782643 ns/op 18754349 B/op 360810 allocs/op
291+
BenchmarkNestedArrayDecode1000-16 1 2227892458 ns/op 1877558216 B/op 36011385 allocs/op
292+
PASS
293+
ok github.com/go-playground/form/v4 4.251s
286294
goos: darwin
287295
goarch: arm64
288296
pkg: github.com/go-playground/form/v4/benchmarks
289-
BenchmarkSimpleUserDecodeStruct-8 8704111 121.1 ns/op 64 B/op 1 allocs/op
290-
BenchmarkSimpleUserDecodeStructParallel-8 35916134 32.89 ns/op 64 B/op 1 allocs/op
291-
BenchmarkSimpleUserEncodeStruct-8 3746173 320.7 ns/op 485 B/op 10 allocs/op
292-
BenchmarkSimpleUserEncodeStructParallel-8 7293147 180.0 ns/op 485 B/op 10 allocs/op
293-
BenchmarkPrimitivesDecodeStructAllPrimitivesTypes-8 2993259 400.5 ns/op 96 B/op 1 allocs/op
294-
BenchmarkPrimitivesDecodeStructAllPrimitivesTypesParallel-8 13023300 97.70 ns/op 96 B/op 1 allocs/op
295-
BenchmarkPrimitivesEncodeStructAllPrimitivesTypes-8 643202 1767 ns/op 2977 B/op 35 allocs/op
296-
BenchmarkPrimitivesEncodeStructAllPrimitivesTypesParallel-8 1000000 1202 ns/op 2978 B/op 35 allocs/op
297-
BenchmarkComplexArrayDecodeStructAllTypes-8 172630 6822 ns/op 2008 B/op 121 allocs/op
298-
BenchmarkComplexArrayDecodeStructAllTypesParallel-8 719788 1735 ns/op 2009 B/op 121 allocs/op
299-
BenchmarkComplexArrayEncodeStructAllTypes-8 197052 5839 ns/op 7087 B/op 104 allocs/op
300-
BenchmarkComplexArrayEncodeStructAllTypesParallel-8 348039 3247 ns/op 7089 B/op 104 allocs/op
301-
BenchmarkComplexMapDecodeStructAllTypes-8 139246 8550 ns/op 5313 B/op 130 allocs/op
302-
BenchmarkComplexMapDecodeStructAllTypesParallel-8 409018 3143 ns/op 5317 B/op 130 allocs/op
303-
BenchmarkComplexMapEncodeStructAllTypes-8 208833 5515 ns/op 4257 B/op 103 allocs/op
304-
BenchmarkComplexMapEncodeStructAllTypesParallel-8 523833 2182 ns/op 4258 B/op 103 allocs/op
305-
BenchmarkDecodeNestedStruct-8 807690 1408 ns/op 344 B/op 14 allocs/op
306-
BenchmarkDecodeNestedStructParallel-8 3409441 359.6 ns/op 344 B/op 14 allocs/op
307-
BenchmarkEncodeNestedStruct-8 1488520 803.6 ns/op 653 B/op 16 allocs/op
308-
BenchmarkEncodeNestedStructParallel-8 3570204 346.6 ns/op 653 B/op 16 allocs/op
297+
cpu: Apple M3 Max
298+
BenchmarkSimpleUserDecodeStruct-16 12669696 94.60 ns/op 64 B/op 1 allocs/op
299+
BenchmarkSimpleUserDecodeStructParallel-16 46715631 27.79 ns/op 64 B/op 1 allocs/op
300+
BenchmarkSimpleUserEncodeStruct-16 4624094 256.7 ns/op 485 B/op 10 allocs/op
301+
BenchmarkSimpleUserEncodeStructParallel-16 7386290 166.2 ns/op 485 B/op 10 allocs/op
302+
BenchmarkPrimitivesDecodeStructAllPrimitivesTypes-16 3533421 332.3 ns/op 96 B/op 1 allocs/op
303+
BenchmarkPrimitivesDecodeStructAllPrimitivesTypesParallel-16 20706642 59.43 ns/op 96 B/op 1 allocs/op
304+
BenchmarkPrimitivesEncodeStructAllPrimitivesTypes-16 1228750 966.4 ns/op 1465 B/op 34 allocs/op
305+
BenchmarkPrimitivesEncodeStructAllPrimitivesTypesParallel-16 1962678 607.2 ns/op 1465 B/op 34 allocs/op
306+
BenchmarkComplexArrayDecodeStructAllTypes-16 213568 5361 ns/op 2081 B/op 121 allocs/op
307+
BenchmarkComplexArrayDecodeStructAllTypesParallel-16 960226 1314 ns/op 2087 B/op 121 allocs/op
308+
BenchmarkComplexArrayEncodeStructAllTypes-16 271944 4017 ns/op 6788 B/op 107 allocs/op
309+
BenchmarkComplexArrayEncodeStructAllTypesParallel-16 441998 2829 ns/op 6791 B/op 107 allocs/op
310+
BenchmarkComplexMapDecodeStructAllTypes-16 179220 6359 ns/op 5300 B/op 130 allocs/op
311+
BenchmarkComplexMapDecodeStructAllTypesParallel-16 412233 2933 ns/op 5310 B/op 130 allocs/op
312+
BenchmarkComplexMapEncodeStructAllTypes-16 262464 4122 ns/op 4083 B/op 106 allocs/op
313+
BenchmarkComplexMapEncodeStructAllTypesParallel-16 622110 2084 ns/op 4084 B/op 106 allocs/op
314+
BenchmarkDecodeNestedStruct-16 823956 1247 ns/op 344 B/op 14 allocs/op
315+
BenchmarkDecodeNestedStructParallel-16 4689418 267.5 ns/op 344 B/op 14 allocs/op
316+
BenchmarkEncodeNestedStruct-16 1844667 636.0 ns/op 653 B/op 16 allocs/op
317+
BenchmarkEncodeNestedStructParallel-16 4302678 278.8 ns/op 653 B/op 16 allocs/op
309318
```
310319

311320
Competitor benchmarks can be found [here](https://github.com/go-playground/form/blob/master/benchmarks/benchmarks.md)
312321

322+
323+
Maintenance and support for SDK major versions
324+
----------------------------------------------
325+
326+
This package is aligned with the [Go release policy](https://go.dev/doc/devel/release) in that support is guaranteed for
327+
the two most recent major versions.
328+
329+
This does not mean the package will not work with older versions of Go, only that we reserve the right to increase the
330+
MSGV(Minimum Supported Go Version) when the need arises to address Security issues/patches, OS issues & support or newly
331+
introduced functionality that would greatly benefit the maintenance and/or usage of this package.
332+
333+
If and when the MSGV is increased it will be done so in a minimum of a `Minor` release bump.
334+
313335
Complimentary Software
314336
----------------------
315337

cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (s *structCacheMap) parseStruct(mode Mode, current reflect.Value, key refle
8282
typ := current.Type()
8383
cs = &cachedStruct{fields: make([]cachedField, 0, 4)} // init 4, betting most structs decoding into have at aleast 4 fields.
8484

85-
numFields := current.NumField()
85+
numFields := typ.NumField()
8686

8787
var fld reflect.StructField
8888
var name string

decoder.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ func (d *decoder) parseMapData() {
5151
if d.aliasMap == nil {
5252
d.aliasMap = make(map[string]*recursiveData)
5353
} else {
54-
for k := range d.aliasMap {
55-
delete(d.aliasMap, k)
56-
}
54+
clear(d.aliasMap)
5755
}
5856

5957
var i int

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/go-playground/form/v4
22

3-
go 1.13
3+
go 1.21
44

55
retract (
6-
v4.2.2 // Accidentally publiches breaking change
76
v4.2.3 // For retractions and revert of that code.
7+
v4.2.2 // Accidentally publiches breaking change
88
)
99

10-
require github.com/go-playground/assert/v2 v2.0.1
10+
require github.com/go-playground/assert/v2 v2.2.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
22
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
3+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
4+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=

0 commit comments

Comments
 (0)