Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compile_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: 1.23
go-version: 1.24
cache-dependency-path: "**/*.sum"
- name: Install dependencies
run: go mod download
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: 1.23
go-version: 1.24
cache-dependency-path: "**/*.sum"
- name: Install dependencies
run: go mod download
Expand Down
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,52 @@ This library aims for strict RFC 6902 compliance including:
- Deep equality comparison for the `test` operation per Section 4.6
- Ignoring unrecognized members in operation objects per Section 4

## License
## Performance & Benchmarking

The library includes comprehensive benchmarks covering all major operations at various scales. Contributors can use these to verify performance improvements or regressions.

### Running Benchmarks

Run all benchmarks with memory allocation stats:

```bash
go test -bench=. -benchmem
```

### Comparing Performance Changes

To compare performance before and after a change, use [`benchstat`](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat):

1. Install benchstat:
```bash
go install golang.org/x/perf/cmd/benchstat@latest
```

2. Collect baseline benchmarks:
```bash
go test -bench=. -benchmem -count=5 > old.txt
```

3. Make your changes and collect new benchmarks:
```bash
go test -bench=. -benchmem -count=5 > new.txt
```

4. Compare results:
```bash
benchstat old.txt new.txt
```

This will show you the performance delta for each benchmark function, including ns/op (time), B/op (memory), and allocs/op changes.

### Benchmark Coverage

The benchmarks include:
- **Apply operations**: Single ops, multi-op sequences, large documents, large patches, nested structures, array operations
- **CreatePatch**: Small and large objects, identical documents, arrays, deep nesting, round-trip scenarios
- **Serialization**: DecodePatch, MarshalPatch
- **Pointer operations**: Parsing, evaluation, modification
- **End-to-end**: Realistic complex object scenarios

## License
MIT
8 changes: 4 additions & 4 deletions apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ func applyTest(doc interface{}, op Operation) (interface{}, error) {
}

// jsonEqual compares two JSON-compatible values for equality per RFC 6902 Section 4.6.
// All callers are expected to pass values already produced by encoding/json
// (i.e., numbers are float64, maps are map[string]interface{}, etc.).
func jsonEqual(a, b interface{}) bool {
// Normalize through JSON round-trip to ensure consistent types
na := normalizeJSON(a)
nb := normalizeJSON(b)
return reflect.DeepEqual(na, nb)
return reflect.DeepEqual(a, b)
}

// normalizeJSON normalizes a value by round-tripping through JSON serialization.
// This ensures consistent types (e.g., all numbers become float64).
// Used by CreatePatchFromValues to normalize caller-supplied values.
func normalizeJSON(v interface{}) interface{} {
b, err := json.Marshal(v)
if err != nil {
Expand Down
Loading
Loading