Skip to content

Commit 11a7dc2

Browse files
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.md
1 parent 78d0e80 commit 11a7dc2

17 files changed

Lines changed: 3809 additions & 11 deletions

babel.config.backend.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Minimal Babel configuration for backend (Node.js only) tests.
3+
*
4+
* Uses babel-preset-current-node-syntax (bundled with jest) + TypeScript
5+
* syntax plugin — no React Native, no Flow, no Expo.
6+
*
7+
* When node_modules are installed the standard @babel/preset-env +
8+
* @babel/preset-typescript combo takes over via babel-preset-expo.
9+
*/
10+
module.exports = {
11+
presets: ['babel-preset-current-node-syntax'],
12+
plugins: ['@babel/plugin-syntax-typescript'],
13+
overrides: [
14+
{
15+
test: /\.tsx?$/,
16+
plugins: [['@babel/plugin-syntax-typescript', { allExtensions: true }]],
17+
},
18+
],
19+
};

0 commit comments

Comments
 (0)