Commit 11a7dc2
committed
feat(perf): implement ContextOptimize performance suite
- Smart contract gas optimization with storage packing (closes #995)
- Database query optimization with index analysis (closes #992)
- API response caching with ETags (closes #993)
- Lazy loading for smart contract modules (closes #989)
Smart contract (contracts/subscription/src/):
- Add storage_packing.rs: HotConfigPack collapses 9 instance-storage
entries into one, saving ~2400 CPU instructions per call; SubscriptionPack
and PlanPack colocate mutable fields; RateLimitPack moves rate-limit
state to auto-expiring temporary storage eliminating permanent growth
- Add lazy_modules.rs: LazyModule<T> and LazyModuleRegistry resolve the 6
optional cross-contract addresses (oracle, invoice, access-control,
fraud, metering, batch) at most once per call; unaccessed modules
save ~300 instructions each; add Cargo feature flags so disabled
modules compile to zero WASM bytes
- Update Cargo.toml: add [features] section with billing, notifications,
analytics, fraud_detection, mev_protection gates
Backend (backend/elasticsearch/, backend/services/shared/):
- Add queryOptimizer.ts: FieldIndex<T> O(log n) sorted-array index;
QueryOptimizer wraps in-process store with automatic index building
for keyword/float/boolean/date fields; produces IndexAnalysisReport
with per-field hit rates, p95/p99 latency, prioritised recommendations
and Prometheus metrics; createSubscriptionQueryOptimizer() factory
- Extend config.ts: add ElasticsearchNode, loadElasticsearchNodes(),
loadElasticsearchConfig() required by replicaRouter.ts
- Add etagCache.ts: RFC 7232 ETag caching on top of ICacheService;
wrap() delivers 304 Not Modified when body unchanged; computeETag()
uses SHA-256 base64url; weak/strong comparison; pattern invalidation;
integrates with applyCompression() for Brotli/gzip; Prometheus metrics
- Export new services from shared/index.ts
Tests:
- queryOptimizer.test.ts: FieldIndex, QueryOptimizer (indexed/unindexed
queries, range, sort, pagination, full-text, index management, analysis
report, Prometheus metrics, factory)
- etagCache.test.ts: computeETag, parseIfNoneMatch, isETagMatch,
wrap() 200/304 flows, producer call-count, wildcard matching,
invalidation, prime/getETag, metrics, Prometheus, factory
Config:
- Add jest.backend.config.js: standalone Jest config for backend tests
- Add babel.config.backend.js: Node-only Babel transform
- Add npm scripts: test:backend, test:backend:coverage
Docs:
- docs/gas-optimization-storage-packing.md
- docs/lazy-module-loading.md
- docs/query-optimization.md
- docs/api-response-etag-cache.md1 parent 78d0e80 commit 11a7dc2
17 files changed
Lines changed: 3809 additions & 11 deletions
File tree
- backend
- elasticsearch
- __tests__
- contracts/subscription
- src
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments