Skip to content
Open
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
37 changes: 37 additions & 0 deletions AUDIT-PERFORMANCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Performance Audit

## Database Performance

Not applicable. This is a library and does not have a database.

## Memory Usage

- **Memory Leaks:** No memory leaks were identified. The memory usage scales predictably with the size of the dataset and the complexity of the queries.

- **Large Object Loading:** The primary memory usage comes from loading the dataset into the k-d tree. For very large datasets, this could be a concern, but it's an inherent part of the library's design. No unnecessary large objects are loaded.

- **Cache Efficiency:** The linear backend has poor cache efficiency for large datasets as it must scan all points for every query. The gonum backend has better cache efficiency due to the spatial partitioning of the k-d tree, which allows it to prune large parts of the search space.

- **Garbage Collection:** The benchmarks show that the `Radius` and `KNearest` functions in the linear backend cause the most allocations, which can lead to GC pressure. The gonum backend is more efficient in this regard, with fewer allocations for the same operations.

## Concurrency

- **Blocking Operations:** The library's operations are CPU-bound and will block the calling goroutine. This is expected behavior for a data structure library.

- **Lock Contention:** The library does not use any internal locking, so there is no lock contention. However, this also means the `KDTree` is not safe for concurrent use. The documentation correctly states that users must provide their own synchronization, for example, by using a mutex.

- **Thread Pool Sizing:** Not applicable. The library does not manage its own thread pool.

- **Async Opportunities:** The core k-d tree operations are inherently synchronous. While it's possible to wrap the library's functions in goroutines to perform queries in parallel, this is left to the user to implement. The library itself does not offer any async APIs.

## API Performance

Not applicable. This is a library and does not have an API.

## Build/Deploy Performance

- **Build Time:** The build process is fast and efficient. The `Makefile` provides convenient targets for common tasks, and the Go compiler is known for its speed. No build performance issues were identified.

- **Asset Size:** As this is a library, there are no assets to consider. The compiled code size is minimal. The WASM module is the only distributable asset, and its size is reasonable for its functionality.

- **Cold Start:** Not applicable. This is a library and does not have a cold start time.
42 changes: 42 additions & 0 deletions gonum_bench.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
goos: linux
goarch: amd64
pkg: github.com/Snider/Poindexter
cpu: Intel(R) Xeon(R) Processor @ 2.30GHz
BenchmarkNearest_Linear_Uniform_100k_2D-4 1384 850417 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_100k_2D-4 825416 1422 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_100k_4D-4 1111 1108445 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_100k_4D-4 159350 16747 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Clustered_100k_2D-4 1156 897493 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Clustered_100k_2D-4 164542 7957 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Clustered_100k_4D-4 1093 1068889 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Clustered_100k_4D-4 679 1839479 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_1k_2D-4 140626 8470 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_1k_2D-4 1417580 721.6 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_10k_2D-4 14460 83143 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_10k_2D-4 1372161 864.0 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_1k_4D-4 112540 11183 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_1k_4D-4 352273 3433 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_10k_4D-4 10000 106582 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_10k_4D-4 183109 6641 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Clustered_1k_2D-4 140745 11324 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Clustered_1k_2D-4 593008 2362 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Clustered_10k_2D-4 14334 101665 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Clustered_10k_2D-4 258667 4285 ns/op 0 B/op 0 allocs/op
BenchmarkKNN10_Linear_Uniform_10k_2D-4 393 2625727 ns/op 164496 B/op 6 allocs/op
BenchmarkKNN10_Gonum_Uniform_10k_2D-4 172296 6853 ns/op 1384 B/op 12 allocs/op
BenchmarkKNN10_Linear_Clustered_10k_2D-4 454 2595619 ns/op 164496 B/op 6 allocs/op
BenchmarkKNN10_Gonum_Clustered_10k_2D-4 97267 11278 ns/op 1384 B/op 12 allocs/op
BenchmarkRadiusMid_Linear_Uniform_10k_2D-4 236 4931056 ns/op 959204 B/op 123 allocs/op
BenchmarkRadiusMid_Gonum_Uniform_10k_2D-4 223 5436124 ns/op 1025664 B/op 129 allocs/op
BenchmarkRadiusMid_Linear_Clustered_10k_2D-4 199 5687141 ns/op 1232172 B/op 165 allocs/op
BenchmarkRadiusMid_Gonum_Clustered_10k_2D-4 182 6186214 ns/op 1315417 B/op 179 allocs/op
BenchmarkNearest_1k_2D-4 1000000 1070 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_10k_2D-4 1908055 1276 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_1k_4D-4 249206 4226 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_10k_4D-4 185893 5574 ns/op 0 B/op 0 allocs/op
BenchmarkKNearest10_1k_2D-4 192446 5614 ns/op 1384 B/op 12 allocs/op
BenchmarkKNearest10_10k_2D-4 171120 10207 ns/op 1384 B/op 12 allocs/op
BenchmarkRadiusMid_1k_2D-4 2348 526415 ns/op 84118 B/op 18 allocs/op
BenchmarkRadiusMid_10k_2D-4 122 10288116 ns/op 1036096 B/op 218 allocs/op
PASS
ok github.com/Snider/Poindexter 70.252s
34 changes: 34 additions & 0 deletions linear_bench.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
goos: linux
goarch: amd64
pkg: github.com/Snider/Poindexter
cpu: Intel(R) Xeon(R) Processor @ 2.30GHz
BenchmarkNearest_Linear_Uniform_1k_2D-4 138124 8534 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_1k_2D-4 133792 8428 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_10k_2D-4 10000 122322 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_10k_2D-4 13287 87229 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_1k_4D-4 119668 10099 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_1k_4D-4 120369 10518 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Uniform_10k_4D-4 12187 95500 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Uniform_10k_4D-4 12282 101452 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Clustered_1k_2D-4 141176 8635 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Clustered_1k_2D-4 141950 9332 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Linear_Clustered_10k_2D-4 13855 100933 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_Gonum_Clustered_10k_2D-4 10000 104974 ns/op 0 B/op 0 allocs/op
BenchmarkKNN10_Linear_Uniform_10k_2D-4 447 2664549 ns/op 164497 B/op 6 allocs/op
BenchmarkKNN10_Gonum_Uniform_10k_2D-4 448 2678659 ns/op 164496 B/op 6 allocs/op
BenchmarkKNN10_Linear_Clustered_10k_2D-4 451 2655975 ns/op 164496 B/op 6 allocs/op
BenchmarkKNN10_Gonum_Clustered_10k_2D-4 429 2796159 ns/op 164496 B/op 6 allocs/op
BenchmarkRadiusMid_Linear_Uniform_10k_2D-4 205 5708833 ns/op 961263 B/op 138 allocs/op
BenchmarkRadiusMid_Gonum_Uniform_10k_2D-4 196 5334473 ns/op 961862 B/op 143 allocs/op
BenchmarkRadiusMid_Linear_Clustered_10k_2D-4 177 9435880 ns/op 1233949 B/op 182 allocs/op
BenchmarkRadiusMid_Gonum_Clustered_10k_2D-4 163 6559096 ns/op 1235333 B/op 196 allocs/op
BenchmarkNearest_1k_2D-4 116074 8685 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_10k_2D-4 14332 91255 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_1k_4D-4 108560 11050 ns/op 0 B/op 0 allocs/op
BenchmarkNearest_10k_4D-4 10000 112694 ns/op 0 B/op 0 allocs/op
BenchmarkKNearest10_1k_2D-4 4704 253934 ns/op 17032 B/op 6 allocs/op
BenchmarkKNearest10_10k_2D-4 458 2664017 ns/op 164495 B/op 6 allocs/op
BenchmarkRadiusMid_1k_2D-4 3313 336997 ns/op 77568 B/op 16 allocs/op
BenchmarkRadiusMid_10k_2D-4 204 6112449 ns/op 969521 B/op 141 allocs/op
PASS
ok github.com/Snider/Poindexter 47.769s
Loading