Merge 5ab3551baf into 86f4e33b1a
This commit is contained in:
commit
3a85d3f2fa
5 changed files with 140 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -11,4 +11,6 @@ test.*
|
|||
/dist/
|
||||
/site/
|
||||
# macOS
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
*.test
|
||||
*.prof
|
||||
|
|
|
|||
59
AUDIT-PERFORMANCE.md
Normal file
59
AUDIT-PERFORMANCE.md
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# Performance Audit Report
|
||||
|
||||
## 1. Database Performance
|
||||
|
||||
Not applicable. The project is a command-line tool and library that does not interface with a database.
|
||||
|
||||
## 2. Memory Usage
|
||||
|
||||
### Memory Leaks
|
||||
- Unbounded growth
|
||||
|
||||
### Large Object Loading
|
||||
- The `cmd/trix/main.go` CLI reads the entire file into memory using `ioutil.ReadAll`. This can lead to high memory consumption for large files. Consider switching to a streaming approach for file processing.
|
||||
|
||||
### Cache Efficiency
|
||||
- Hit rates, eviction
|
||||
|
||||
### Garbage Collection
|
||||
- GC pressure
|
||||
|
||||
## 3. Concurrency
|
||||
|
||||
The `trix` CLI tool operates entirely in a single-threaded manner. All I/O operations are blocking and are performed on the main thread. While this is acceptable for a simple command-line tool, it could be a performance bottleneck if the tool were to be used in a high-throughput environment.
|
||||
|
||||
### Async Opportunities
|
||||
- The `trix` tool could be improved by using asynchronous I/O for file operations. This would allow the tool to perform other tasks while waiting for I/O to complete, which could improve performance for large files.
|
||||
|
||||
## 4. API Performance
|
||||
|
||||
### Response Times
|
||||
- P50, P95, P99
|
||||
|
||||
### Payload Sizes
|
||||
- Compression, pagination
|
||||
|
||||
### Caching Headers
|
||||
- ETags, Cache-Control
|
||||
|
||||
### Rate Limiting
|
||||
- Prevents overload?
|
||||
|
||||
## 5. Build/Deploy Performance
|
||||
|
||||
### Build Time
|
||||
- Can be parallelized?
|
||||
|
||||
### Asset Size
|
||||
- Bundle optimization
|
||||
|
||||
### Cold Start
|
||||
- Initialization time
|
||||
|
||||
## 6. Benchmarks
|
||||
|
||||
### `pkg/trix` Package
|
||||
|
||||
- `BenchmarkPack-4 3307 473778 ns/op 814258 B/op 23 allocs/op`
|
||||
|
||||
This benchmark measures the performance of the `trix.Pack` method with `base64` and `gzip` sigils.
|
||||
29
pkg/crypt/crypt_benchmark_test.go
Normal file
29
pkg/crypt/crypt_benchmark_test.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package crypt
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var service = NewService()
|
||||
|
||||
func BenchmarkHash(b *testing.B) {
|
||||
payload := "hello, world"
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
service.Hash(SHA256, payload)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGenerateRSAKeyPair(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, _, err := service.GenerateRSAKeyPair(2048)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
pkg/enchantrix/enchantrix_benchmark_test.go
Normal file
24
pkg/enchantrix/enchantrix_benchmark_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package enchantrix
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkTransmute(b *testing.B) {
|
||||
data := []byte("hello, world")
|
||||
sigils := []Sigil{
|
||||
&Base64Sigil{},
|
||||
&GzipSigil{},
|
||||
&HexSigil{},
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := Transmute(data, sigils)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
25
pkg/trix/trix_benchmark_test.go
Normal file
25
pkg/trix/trix_benchmark_test.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package trix
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkPack(b *testing.B) {
|
||||
t := &Trix{
|
||||
Payload: []byte("hello, world this is a test payload for benchmarking"),
|
||||
InSigils: []string{"base64", "gzip"},
|
||||
}
|
||||
originalPayload := t.Payload
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
// Reset payload before each run to ensure we're not re-packing packed data
|
||||
t.Payload = make([]byte, len(originalPayload))
|
||||
copy(t.Payload, originalPayload)
|
||||
if err := t.Pack(); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue