@coherent.js/core 1.0.0-beta.6 → 1.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coherent.d.ts +150 -10
- package/dist/coherent.d.ts.map +1 -1
- package/dist/coherent.js +166 -33
- package/dist/coherent.js.map +1 -1
- package/dist/components/component-system.js +109 -109
- package/dist/components/lifecycle.d.ts +212 -0
- package/dist/components/lifecycle.d.ts.map +1 -0
- package/dist/components/lifecycle.js +525 -0
- package/dist/components/lifecycle.js.map +1 -0
- package/dist/core/html-utils.js +5 -5
- package/dist/core/object-factory.js +21 -21
- package/dist/core/object-utils.js +2 -2
- package/dist/dev/dev-tools.d.ts +1 -1
- package/dist/dev/dev-tools.js +28 -28
- package/dist/forms/validation.d.ts +271 -0
- package/dist/forms/validation.d.ts.map +1 -0
- package/dist/forms/validation.js +573 -0
- package/dist/forms/validation.js.map +1 -0
- package/dist/index.cjs +185 -28
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +181 -29
- package/dist/index.js.map +4 -4
- package/dist/performance/bundle-optimizer.js +11 -11
- package/dist/performance/cache-manager.js +6 -6
- package/dist/performance/component-cache.d.ts +120 -0
- package/dist/performance/component-cache.d.ts.map +1 -0
- package/dist/performance/component-cache.js +364 -0
- package/dist/performance/component-cache.js.map +1 -0
- package/dist/performance/monitor.js +10 -10
- package/dist/performance/monitor.js.map +1 -1
- package/dist/rendering/base-renderer.js +13 -13
- package/dist/rendering/css-manager.d.ts +73 -0
- package/dist/rendering/css-manager.d.ts.map +1 -0
- package/dist/rendering/css-manager.js +176 -0
- package/dist/rendering/css-manager.js.map +1 -0
- package/dist/rendering/dom-renderer.d.ts +23 -0
- package/dist/rendering/dom-renderer.d.ts.map +1 -1
- package/dist/rendering/dom-renderer.js +77 -9
- package/dist/rendering/dom-renderer.js.map +1 -1
- package/dist/rendering/html-renderer.d.ts +15 -0
- package/dist/rendering/html-renderer.d.ts.map +1 -1
- package/dist/rendering/html-renderer.js +85 -4
- package/dist/rendering/html-renderer.js.map +1 -1
- package/dist/rendering/streaming-renderer.js +12 -12
- package/dist/rendering/vdom-diff.d.ts +47 -0
- package/dist/rendering/vdom-diff.d.ts.map +1 -0
- package/dist/rendering/vdom-diff.js +416 -0
- package/dist/rendering/vdom-diff.js.map +1 -0
- package/dist/routing/router.d.ts +241 -0
- package/dist/routing/router.d.ts.map +1 -0
- package/dist/routing/router.js +648 -0
- package/dist/routing/router.js.map +1 -0
- package/dist/state/reactive-state.d.ts +166 -0
- package/dist/state/reactive-state.d.ts.map +1 -0
- package/dist/state/reactive-state.js +546 -0
- package/dist/state/reactive-state.js.map +1 -0
- package/dist/utils/dependency-utils.js +2 -2
- package/dist/utils/error-handler.d.ts +148 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +468 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/normalization.js +1 -1
- package/dist/utils/validation.js +1 -1
- package/package.json +5 -1
- package/dist/database/adapters/mongodb.d.ts +0 -15
- package/dist/database/adapters/mongodb.d.ts.map +0 -1
- package/dist/database/adapters/mongodb.js +0 -216
- package/dist/database/adapters/mongodb.js.map +0 -1
- package/dist/database/adapters/mysql.d.ts +0 -12
- package/dist/database/adapters/mysql.d.ts.map +0 -1
- package/dist/database/adapters/mysql.js +0 -171
- package/dist/database/adapters/mysql.js.map +0 -1
- package/dist/database/adapters/postgresql.d.ts +0 -12
- package/dist/database/adapters/postgresql.d.ts.map +0 -1
- package/dist/database/adapters/postgresql.js +0 -177
- package/dist/database/adapters/postgresql.js.map +0 -1
- package/dist/database/adapters/sqlite.d.ts +0 -15
- package/dist/database/adapters/sqlite.d.ts.map +0 -1
- package/dist/database/adapters/sqlite.js +0 -241
- package/dist/database/adapters/sqlite.js.map +0 -1
- package/dist/database/connection-manager.d.ts +0 -135
- package/dist/database/connection-manager.d.ts.map +0 -1
- package/dist/database/connection-manager.js +0 -362
- package/dist/database/connection-manager.js.map +0 -1
- package/dist/database/index.d.ts +0 -38
- package/dist/database/index.d.ts.map +0 -1
- package/dist/database/index.js +0 -60
- package/dist/database/index.js.map +0 -1
- package/dist/database/middleware.d.ts +0 -122
- package/dist/database/middleware.d.ts.map +0 -1
- package/dist/database/middleware.js +0 -390
- package/dist/database/middleware.js.map +0 -1
- package/dist/database/migration.d.ts +0 -62
- package/dist/database/migration.d.ts.map +0 -1
- package/dist/database/migration.js +0 -423
- package/dist/database/migration.js.map +0 -1
- package/dist/database/model.d.ts +0 -8
- package/dist/database/model.d.ts.map +0 -1
- package/dist/database/model.js +0 -167
- package/dist/database/model.js.map +0 -1
- package/dist/database/query-builder.d.ts +0 -111
- package/dist/database/query-builder.d.ts.map +0 -1
- package/dist/database/query-builder.js +0 -187
- package/dist/database/query-builder.js.map +0 -1
- package/dist/database/utils.d.ts +0 -196
- package/dist/database/utils.d.ts.map +0 -1
- package/dist/database/utils.js +0 -372
- package/dist/database/utils.js.map +0 -1
|
@@ -18,23 +18,23 @@ export class BundleOptimizer {
|
|
|
18
18
|
this.traverseComponent(rootComponent, props, analysisContext);
|
|
19
19
|
return this.generateOptimizationReport();
|
|
20
20
|
}
|
|
21
|
-
traverseComponent(component, props,
|
|
21
|
+
traverseComponent(component, props, _context) {
|
|
22
22
|
const componentName = this.getComponentName(component);
|
|
23
23
|
// Track component usage
|
|
24
24
|
this.usedComponents.add(componentName);
|
|
25
25
|
context.componentStack.push(componentName);
|
|
26
26
|
// Track props flow for optimization
|
|
27
|
-
context.propsFlow.set(componentName, Object.keys(
|
|
27
|
+
context.propsFlow.set(componentName, Object.keys(_props));
|
|
28
28
|
// Analyze component implementation
|
|
29
29
|
if (typeof component === 'function') {
|
|
30
|
-
this.analyzeFunctionComponent(component, props,
|
|
30
|
+
this.analyzeFunctionComponent(component, props, _context);
|
|
31
31
|
}
|
|
32
32
|
else if (typeof component === 'object') {
|
|
33
|
-
this.analyzeObjectComponent(component,
|
|
33
|
+
this.analyzeObjectComponent(component, _context);
|
|
34
34
|
}
|
|
35
35
|
context.componentStack.pop();
|
|
36
36
|
}
|
|
37
|
-
analyzeFunctionComponent(component, props,
|
|
37
|
+
analyzeFunctionComponent(component, props, _context) {
|
|
38
38
|
const componentStr = component.toString();
|
|
39
39
|
// Detect conditional rendering patterns
|
|
40
40
|
const conditionalPatterns = [
|
|
@@ -50,20 +50,20 @@ export class BundleOptimizer {
|
|
|
50
50
|
}
|
|
51
51
|
// Try to execute with sample props to discover runtime paths
|
|
52
52
|
try {
|
|
53
|
-
const result = component(
|
|
53
|
+
const result = component(_props);
|
|
54
54
|
if (result) {
|
|
55
|
-
this.traverseComponent(result, {},
|
|
55
|
+
this.traverseComponent(result, {}, _context);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
catch {
|
|
59
59
|
// Component might need specific props, skip runtime analysis
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
analyzeObjectComponent(obj,
|
|
62
|
+
analyzeObjectComponent(obj, _context) {
|
|
63
63
|
if (Array.isArray(obj)) {
|
|
64
64
|
obj.forEach(item => {
|
|
65
65
|
if (item && typeof item === 'object') {
|
|
66
|
-
this.traverseComponent(item, {},
|
|
66
|
+
this.traverseComponent(item, {}, _context);
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
return;
|
|
@@ -79,11 +79,11 @@ export class BundleOptimizer {
|
|
|
79
79
|
if (props.children) {
|
|
80
80
|
if (Array.isArray(props.children)) {
|
|
81
81
|
props.children.forEach(child => {
|
|
82
|
-
this.traverseComponent(child, {},
|
|
82
|
+
this.traverseComponent(child, {}, _context);
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
this.traverseComponent(props.children, {},
|
|
86
|
+
this.traverseComponent(props.children, {}, _context);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -79,8 +79,8 @@ export function createCacheManager(options = {}) {
|
|
|
79
79
|
const componentStr = typeof component === 'function'
|
|
80
80
|
? component.name || component.toString()
|
|
81
81
|
: JSON.stringify(component);
|
|
82
|
-
const propsStr = JSON.stringify(props, Object.keys(
|
|
83
|
-
const contextStr = JSON.stringify(
|
|
82
|
+
const propsStr = JSON.stringify(props, Object.keys(_props).sort());
|
|
83
|
+
const contextStr = JSON.stringify(_context);
|
|
84
84
|
const hash = simpleHash(componentStr + propsStr + contextStr);
|
|
85
85
|
return `${extractComponentName(component)}_${hash}`;
|
|
86
86
|
}
|
|
@@ -92,7 +92,7 @@ export function createCacheManager(options = {}) {
|
|
|
92
92
|
*/
|
|
93
93
|
function get(key, type = 'component') {
|
|
94
94
|
const cache = caches[type] || caches.component;
|
|
95
|
-
const
|
|
95
|
+
const _entry = cache.get(key);
|
|
96
96
|
if (!entry) {
|
|
97
97
|
stats.misses++;
|
|
98
98
|
if (enableStatistics)
|
|
@@ -132,7 +132,7 @@ export function createCacheManager(options = {}) {
|
|
|
132
132
|
if (memoryUsage + size > maxMemoryMB * 1024 * 1024) {
|
|
133
133
|
optimize(type, size);
|
|
134
134
|
}
|
|
135
|
-
const
|
|
135
|
+
const _entry = {
|
|
136
136
|
value,
|
|
137
137
|
timestamp: Date.now(),
|
|
138
138
|
lastAccess: Date.now(),
|
|
@@ -163,7 +163,7 @@ export function createCacheManager(options = {}) {
|
|
|
163
163
|
const cache = caches[type];
|
|
164
164
|
if (!cache)
|
|
165
165
|
return false;
|
|
166
|
-
const
|
|
166
|
+
const _entry = cache.get(key);
|
|
167
167
|
if (entry) {
|
|
168
168
|
updateMemoryUsage(-entry.size);
|
|
169
169
|
return cache.delete(key);
|
|
@@ -172,7 +172,7 @@ export function createCacheManager(options = {}) {
|
|
|
172
172
|
}
|
|
173
173
|
// Check all caches if no type specified
|
|
174
174
|
for (const [, cache] of Object.entries(caches)) {
|
|
175
|
-
const
|
|
175
|
+
const _entry = cache.get(key);
|
|
176
176
|
if (entry) {
|
|
177
177
|
updateMemoryUsage(-entry.size);
|
|
178
178
|
return cache.delete(key);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a new component cache instance
|
|
3
|
+
*/
|
|
4
|
+
export function createComponentCache(options?: {}): ComponentCache;
|
|
5
|
+
/**
|
|
6
|
+
* Memoization decorator for components
|
|
7
|
+
*/
|
|
8
|
+
export function memoize(component: any, keyGenerator: any, options?: {}): (...args: any[]) => any;
|
|
9
|
+
/**
|
|
10
|
+
* Component Cache Manager with intelligent invalidation
|
|
11
|
+
*/
|
|
12
|
+
export class ComponentCache {
|
|
13
|
+
constructor(options?: {});
|
|
14
|
+
options: {
|
|
15
|
+
maxSize: any;
|
|
16
|
+
defaultTTL: any;
|
|
17
|
+
cleanupInterval: any;
|
|
18
|
+
enableStats: boolean;
|
|
19
|
+
};
|
|
20
|
+
cache: Map<any, any>;
|
|
21
|
+
dependencies: Map<any, any>;
|
|
22
|
+
stats: {
|
|
23
|
+
hits: number;
|
|
24
|
+
misses: number;
|
|
25
|
+
evictions: number;
|
|
26
|
+
cleanups: number;
|
|
27
|
+
invalidations: number;
|
|
28
|
+
};
|
|
29
|
+
cleanupTimer: NodeJS.Timeout | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Generate cache key from component and props
|
|
32
|
+
*/
|
|
33
|
+
generateKey(component: any, props?: {}, context?: {}): string;
|
|
34
|
+
/**
|
|
35
|
+
* Serialize component for cache key generation
|
|
36
|
+
*/
|
|
37
|
+
serializeComponent(component: any, maxDepth?: number, currentDepth?: number): any;
|
|
38
|
+
/**
|
|
39
|
+
* Get component from cache
|
|
40
|
+
*/
|
|
41
|
+
get(key: any, dependencies?: any[]): any;
|
|
42
|
+
/**
|
|
43
|
+
* Set component in cache
|
|
44
|
+
*/
|
|
45
|
+
set(key: any, component: any, options?: {}): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Check if component exists in cache
|
|
48
|
+
*/
|
|
49
|
+
has(key: any): any;
|
|
50
|
+
/**
|
|
51
|
+
* Invalidate cache entries by dependency
|
|
52
|
+
*/
|
|
53
|
+
invalidate(dependency: any): number;
|
|
54
|
+
/**
|
|
55
|
+
* Invalidate multiple dependencies
|
|
56
|
+
*/
|
|
57
|
+
invalidateMultiple(dependencies: any): number;
|
|
58
|
+
/**
|
|
59
|
+
* Clear entire cache
|
|
60
|
+
*/
|
|
61
|
+
clear(): number;
|
|
62
|
+
/**
|
|
63
|
+
* Add dependency mapping
|
|
64
|
+
*/
|
|
65
|
+
addDependencyMapping(dependency: any, key: any): void;
|
|
66
|
+
/**
|
|
67
|
+
* Remove dependency mappings for a cache key
|
|
68
|
+
*/
|
|
69
|
+
removeDependencyMappings(key: any): void;
|
|
70
|
+
/**
|
|
71
|
+
* Evict least recently used entry
|
|
72
|
+
*/
|
|
73
|
+
evictLeastUsed(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Cleanup expired entries
|
|
76
|
+
*/
|
|
77
|
+
cleanup(): number;
|
|
78
|
+
/**
|
|
79
|
+
* Get cache statistics
|
|
80
|
+
*/
|
|
81
|
+
getStats(): {
|
|
82
|
+
size: number;
|
|
83
|
+
maxSize: any;
|
|
84
|
+
hits: number;
|
|
85
|
+
misses: number;
|
|
86
|
+
hitRate: string | number;
|
|
87
|
+
evictions: number;
|
|
88
|
+
cleanups: number;
|
|
89
|
+
invalidations: number;
|
|
90
|
+
dependencies: number;
|
|
91
|
+
memoryUsage: number;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Estimate memory usage (rough approximation)
|
|
95
|
+
*/
|
|
96
|
+
estimateMemoryUsage(): number;
|
|
97
|
+
/**
|
|
98
|
+
* Get hot path components (most accessed)
|
|
99
|
+
*/
|
|
100
|
+
getHotComponents(limit?: number): {
|
|
101
|
+
key: any;
|
|
102
|
+
accessCount: any;
|
|
103
|
+
component: any;
|
|
104
|
+
dependencies: any[];
|
|
105
|
+
}[];
|
|
106
|
+
/**
|
|
107
|
+
* Get cache recommendations
|
|
108
|
+
*/
|
|
109
|
+
getRecommendations(): {
|
|
110
|
+
type: string;
|
|
111
|
+
message: string;
|
|
112
|
+
priority: string;
|
|
113
|
+
}[];
|
|
114
|
+
/**
|
|
115
|
+
* Destroy cache and cleanup
|
|
116
|
+
*/
|
|
117
|
+
destroy(): void;
|
|
118
|
+
}
|
|
119
|
+
export default ComponentCache;
|
|
120
|
+
//# sourceMappingURL=component-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-cache.d.ts","sourceRoot":"","sources":["../../../../src/performance/component-cache.js"],"names":[],"mappings":"AA2YA;;GAEG;AACH,mEAEC;AAED;;GAEG;AACH,2EAMsC,GAAG,WAAI,SAY5C;AA3XD;;GAEG;AACH;IACI,0BAyBC;IAxBG;;;;;MAMC;IAED,qBAAsB;IACtB,4BAA6B;IAC7B;;;;;;MAMC;IAIG,yCAEgC;IAIxC;;OAEG;IACH,8DAiBC;IAED;;OAEG;IACH,kFAyBC;IAED;;OAEG;IACH,yCA2BC;IAED;;OAEG;IACH,qDAoBC;IAED;;OAEG;IACH,mBAGC;IAED;;OAEG;IACH,oCAgBC;IAED;;OAEG;IACH,8CAMC;IAED;;OAEG;IACH,gBAKC;IAED;;OAEG;IACH,sDAKC;IAED;;OAEG;IACH,yCAOC;IAED;;OAEG;IACH,uBAgBC;IAED;;OAEG;IACH,kBAqBC;IAED;;OAEG;IACH;;;;;;;;;;;MAcC;IAED;;OAEG;IACH,8BAOC;IAED;;OAEG;IACH;;;;;QAWC;IAED;;OAEG;IACH;;;;QA6BC;IAED;;OAEG;IACH,gBAKC;CACJ"}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced Component Caching System for Coherent.js
|
|
3
|
+
* Provides intelligent caching with dependency tracking and invalidation
|
|
4
|
+
*/
|
|
5
|
+
import { deepClone } from '../core/object-utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Cache entry structure
|
|
8
|
+
*/
|
|
9
|
+
class CacheEntry {
|
|
10
|
+
constructor(key, component, deps = [], options = {}) {
|
|
11
|
+
this.key = key;
|
|
12
|
+
this.component = deepClone(component);
|
|
13
|
+
this.deps = new Set(deps);
|
|
14
|
+
this.createdAt = Date.now();
|
|
15
|
+
this.lastAccessed = Date.now();
|
|
16
|
+
this.accessCount = 1;
|
|
17
|
+
this.ttl = options.ttl || 300000; // 5 minutes default
|
|
18
|
+
this.persistent = options.persistent || false;
|
|
19
|
+
}
|
|
20
|
+
isExpired() {
|
|
21
|
+
return !this.persistent && (Date.now() - this.createdAt) > this.ttl;
|
|
22
|
+
}
|
|
23
|
+
touch() {
|
|
24
|
+
this.lastAccessed = Date.now();
|
|
25
|
+
this.accessCount++;
|
|
26
|
+
}
|
|
27
|
+
hasDependency(dep) {
|
|
28
|
+
return this.deps.has(dep);
|
|
29
|
+
}
|
|
30
|
+
addDependency(dep) {
|
|
31
|
+
this.deps.add(dep);
|
|
32
|
+
}
|
|
33
|
+
removeDependency(dep) {
|
|
34
|
+
this.deps.delete(dep);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Component Cache Manager with intelligent invalidation
|
|
39
|
+
*/
|
|
40
|
+
export class ComponentCache {
|
|
41
|
+
constructor(options = {}) {
|
|
42
|
+
this.options = {
|
|
43
|
+
maxSize: options.maxSize || 1000,
|
|
44
|
+
defaultTTL: options.defaultTTL || 300000,
|
|
45
|
+
cleanupInterval: options.cleanupInterval || 60000, // 1 minute
|
|
46
|
+
enableStats: options.enableStats !== false,
|
|
47
|
+
...options
|
|
48
|
+
};
|
|
49
|
+
this.cache = new Map();
|
|
50
|
+
this.dependencies = new Map(); // dependency -> Set of cache keys
|
|
51
|
+
this.stats = {
|
|
52
|
+
hits: 0,
|
|
53
|
+
misses: 0,
|
|
54
|
+
evictions: 0,
|
|
55
|
+
cleanups: 0,
|
|
56
|
+
invalidations: 0
|
|
57
|
+
};
|
|
58
|
+
// Start periodic cleanup
|
|
59
|
+
if (this.options.cleanupInterval > 0) {
|
|
60
|
+
this.cleanupTimer = setInterval(() => {
|
|
61
|
+
this.cleanup();
|
|
62
|
+
}, this.options.cleanupInterval);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Generate cache key from component and props
|
|
67
|
+
*/
|
|
68
|
+
generateKey(component, props = {}, context = {}) {
|
|
69
|
+
if (typeof component === 'string') {
|
|
70
|
+
return `str:${component}`;
|
|
71
|
+
}
|
|
72
|
+
if (typeof component === 'function') {
|
|
73
|
+
return `fn:${component.name || 'anonymous'}:${JSON.stringify(_props)}`;
|
|
74
|
+
}
|
|
75
|
+
if (typeof component === 'object' && component !== null) {
|
|
76
|
+
const serialized = this.serializeComponent(component);
|
|
77
|
+
const propsHash = Object.keys(_props).length > 0 ? `:${JSON.stringify(_props)}` : '';
|
|
78
|
+
const contextHash = Object.keys(_context).length > 0 ? `:${JSON.stringify(_context)}` : '';
|
|
79
|
+
return `obj:${serialized}${propsHash}${contextHash}`;
|
|
80
|
+
}
|
|
81
|
+
return `primitive:${String(component)}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Serialize component for cache key generation
|
|
85
|
+
*/
|
|
86
|
+
serializeComponent(component, maxDepth = 3, currentDepth = 0) {
|
|
87
|
+
if (currentDepth > maxDepth) {
|
|
88
|
+
return '[DEEP]';
|
|
89
|
+
}
|
|
90
|
+
if (typeof component !== 'object' || component === null) {
|
|
91
|
+
return String(component);
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(component)) {
|
|
94
|
+
return `[${component.map(item => this.serializeComponent(item, maxDepth, currentDepth + 1)).join(',')}]`;
|
|
95
|
+
}
|
|
96
|
+
const entries = Object.entries(component);
|
|
97
|
+
if (entries.length === 1) {
|
|
98
|
+
const [key, value] = entries[0];
|
|
99
|
+
const serializedValue = typeof value === 'object'
|
|
100
|
+
? this.serializeComponent(value, maxDepth, currentDepth + 1)
|
|
101
|
+
: String(value);
|
|
102
|
+
return `${key}:${serializedValue}`;
|
|
103
|
+
}
|
|
104
|
+
return '[COMPLEX]';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get component from cache
|
|
108
|
+
*/
|
|
109
|
+
get(key, dependencies = []) {
|
|
110
|
+
const _entry = this.cache.get(key);
|
|
111
|
+
if (!entry) {
|
|
112
|
+
this.stats.misses++;
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (entry.isExpired()) {
|
|
116
|
+
this.cache.delete(key);
|
|
117
|
+
this.removeDependencyMappings(key);
|
|
118
|
+
this.stats.misses++;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
entry.touch();
|
|
122
|
+
this.stats.hits++;
|
|
123
|
+
// Update dependency tracking
|
|
124
|
+
dependencies.forEach(dep => {
|
|
125
|
+
if (!entry.hasDependency(dep)) {
|
|
126
|
+
entry.addDependency(dep);
|
|
127
|
+
this.addDependencyMapping(dep, key);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return deepClone(entry.component);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Set component in cache
|
|
134
|
+
*/
|
|
135
|
+
set(key, component, options = {}) {
|
|
136
|
+
// Enforce size limit
|
|
137
|
+
if (this.cache.size >= this.options.maxSize) {
|
|
138
|
+
this.evictLeastUsed();
|
|
139
|
+
}
|
|
140
|
+
const deps = options.dependencies || [];
|
|
141
|
+
const _entry = new CacheEntry(key, component, deps, {
|
|
142
|
+
ttl: options.ttl || this.options.defaultTTL,
|
|
143
|
+
persistent: options.persistent || false
|
|
144
|
+
});
|
|
145
|
+
this.cache.set(key, entry);
|
|
146
|
+
// Update dependency mappings
|
|
147
|
+
deps.forEach(dep => {
|
|
148
|
+
this.addDependencyMapping(dep, key);
|
|
149
|
+
});
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check if component exists in cache
|
|
154
|
+
*/
|
|
155
|
+
has(key) {
|
|
156
|
+
const _entry = this.cache.get(key);
|
|
157
|
+
return entry && !entry.isExpired();
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Invalidate cache entries by dependency
|
|
161
|
+
*/
|
|
162
|
+
invalidate(dependency) {
|
|
163
|
+
const dependentKeys = this.dependencies.get(dependency);
|
|
164
|
+
if (!dependentKeys) {
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
let invalidated = 0;
|
|
168
|
+
for (const key of dependentKeys) {
|
|
169
|
+
if (this.cache.delete(key)) {
|
|
170
|
+
invalidated++;
|
|
171
|
+
this.stats.invalidations++;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
this.dependencies.delete(dependency);
|
|
175
|
+
return invalidated;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Invalidate multiple dependencies
|
|
179
|
+
*/
|
|
180
|
+
invalidateMultiple(dependencies) {
|
|
181
|
+
let totalInvalidated = 0;
|
|
182
|
+
dependencies.forEach(dep => {
|
|
183
|
+
totalInvalidated += this.invalidate(dep);
|
|
184
|
+
});
|
|
185
|
+
return totalInvalidated;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Clear entire cache
|
|
189
|
+
*/
|
|
190
|
+
clear() {
|
|
191
|
+
const size = this.cache.size;
|
|
192
|
+
this.cache.clear();
|
|
193
|
+
this.dependencies.clear();
|
|
194
|
+
return size;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Add dependency mapping
|
|
198
|
+
*/
|
|
199
|
+
addDependencyMapping(dependency, key) {
|
|
200
|
+
if (!this.dependencies.has(dependency)) {
|
|
201
|
+
this.dependencies.set(dependency, new Set());
|
|
202
|
+
}
|
|
203
|
+
this.dependencies.get(dependency).add(key);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Remove dependency mappings for a cache key
|
|
207
|
+
*/
|
|
208
|
+
removeDependencyMappings(key) {
|
|
209
|
+
for (const [dep, keys] of this.dependencies.entries()) {
|
|
210
|
+
keys.delete(key);
|
|
211
|
+
if (keys.size === 0) {
|
|
212
|
+
this.dependencies.delete(dep);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Evict least recently used entry
|
|
218
|
+
*/
|
|
219
|
+
evictLeastUsed() {
|
|
220
|
+
let oldestKey = null;
|
|
221
|
+
let oldestTime = Date.now();
|
|
222
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
223
|
+
if (!entry.persistent && entry.lastAccessed < oldestTime) {
|
|
224
|
+
oldestTime = entry.lastAccessed;
|
|
225
|
+
oldestKey = key;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (oldestKey) {
|
|
229
|
+
this.cache.delete(oldestKey);
|
|
230
|
+
this.removeDependencyMappings(oldestKey);
|
|
231
|
+
this.stats.evictions++;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Cleanup expired entries
|
|
236
|
+
*/
|
|
237
|
+
cleanup() {
|
|
238
|
+
const before = this.cache.size;
|
|
239
|
+
const expiredKeys = [];
|
|
240
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
241
|
+
if (entry.isExpired()) {
|
|
242
|
+
expiredKeys.push(key);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
expiredKeys.forEach(key => {
|
|
246
|
+
this.cache.delete(key);
|
|
247
|
+
this.removeDependencyMappings(key);
|
|
248
|
+
});
|
|
249
|
+
const cleaned = before - this.cache.size;
|
|
250
|
+
if (cleaned > 0) {
|
|
251
|
+
this.stats.cleanups++;
|
|
252
|
+
}
|
|
253
|
+
return cleaned;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get cache statistics
|
|
257
|
+
*/
|
|
258
|
+
getStats() {
|
|
259
|
+
const totalRequests = this.stats.hits + this.stats.misses;
|
|
260
|
+
return {
|
|
261
|
+
size: this.cache.size,
|
|
262
|
+
maxSize: this.options.maxSize,
|
|
263
|
+
hits: this.stats.hits,
|
|
264
|
+
misses: this.stats.misses,
|
|
265
|
+
hitRate: totalRequests > 0 ? (this.stats.hits / totalRequests * 100).toFixed(2) : 0,
|
|
266
|
+
evictions: this.stats.evictions,
|
|
267
|
+
cleanups: this.stats.cleanups,
|
|
268
|
+
invalidations: this.stats.invalidations,
|
|
269
|
+
dependencies: this.dependencies.size,
|
|
270
|
+
memoryUsage: this.estimateMemoryUsage()
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Estimate memory usage (rough approximation)
|
|
275
|
+
*/
|
|
276
|
+
estimateMemoryUsage() {
|
|
277
|
+
let totalSize = 0;
|
|
278
|
+
for (const entry of this.cache.values()) {
|
|
279
|
+
// Rough estimate: 1KB per component + overhead
|
|
280
|
+
totalSize += JSON.stringify(entry.component).length + 500;
|
|
281
|
+
}
|
|
282
|
+
return Math.round(totalSize / 1024); // Return in KB
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get hot path components (most accessed)
|
|
286
|
+
*/
|
|
287
|
+
getHotComponents(limit = 10) {
|
|
288
|
+
const entries = Array.from(this.cache.entries());
|
|
289
|
+
return entries
|
|
290
|
+
.sort((a, b) => b[1].accessCount - a[1].accessCount)
|
|
291
|
+
.slice(0, limit)
|
|
292
|
+
.map(([key, entry]) => ({
|
|
293
|
+
key,
|
|
294
|
+
accessCount: entry.accessCount,
|
|
295
|
+
component: entry.component,
|
|
296
|
+
dependencies: Array.from(entry.deps)
|
|
297
|
+
}));
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Get cache recommendations
|
|
301
|
+
*/
|
|
302
|
+
getRecommendations() {
|
|
303
|
+
const stats = this.getStats();
|
|
304
|
+
const recommendations = [];
|
|
305
|
+
if (stats.hitRate < 50) {
|
|
306
|
+
recommendations.push({
|
|
307
|
+
type: 'low-hit-rate',
|
|
308
|
+
message: `Hit rate is ${stats.hitRate}%. Consider increasing cache size or TTL.`,
|
|
309
|
+
priority: 'HIGH'
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (stats.evictions > stats.hits * 0.1) {
|
|
313
|
+
recommendations.push({
|
|
314
|
+
type: 'frequent-evictions',
|
|
315
|
+
message: 'Frequent evictions detected. Consider increasing maxSize.',
|
|
316
|
+
priority: 'MEDIUM'
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if (stats.invalidations > stats.hits * 0.05) {
|
|
320
|
+
recommendations.push({
|
|
321
|
+
type: 'frequent-invalidations',
|
|
322
|
+
message: 'Frequent invalidations. Review dependency tracking.',
|
|
323
|
+
priority: 'LOW'
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return recommendations;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Destroy cache and cleanup
|
|
330
|
+
*/
|
|
331
|
+
destroy() {
|
|
332
|
+
if (this.cleanupTimer) {
|
|
333
|
+
clearInterval(this.cleanupTimer);
|
|
334
|
+
}
|
|
335
|
+
this.clear();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Create a new component cache instance
|
|
340
|
+
*/
|
|
341
|
+
export function createComponentCache(options = {}) {
|
|
342
|
+
return new ComponentCache(options);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Memoization decorator for components
|
|
346
|
+
*/
|
|
347
|
+
export function memoize(component, keyGenerator, options = {}) {
|
|
348
|
+
const cache = new ComponentCache({
|
|
349
|
+
maxSize: options.maxSize || 100,
|
|
350
|
+
defaultTTL: options.ttl || 300000
|
|
351
|
+
});
|
|
352
|
+
return function memoizedComponent(...args) {
|
|
353
|
+
const key = keyGenerator ? keyGenerator(...args) : JSON.stringify(args);
|
|
354
|
+
const cached = cache.get(key, options.dependencies);
|
|
355
|
+
if (cached) {
|
|
356
|
+
return cached;
|
|
357
|
+
}
|
|
358
|
+
const result = typeof component === 'function' ? component(...args) : component;
|
|
359
|
+
cache.set(key, result, options);
|
|
360
|
+
return result;
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
export default ComponentCache;
|
|
364
|
+
//# sourceMappingURL=component-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-cache.js","sourceRoot":"","sources":["../../../../src/performance/component-cache.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD;;GAEG;AACH,MAAM,UAAU;IACZ,YAAY,GAAG,EAAE,SAAS,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE;QAC/C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,oBAAoB;QACtD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC;IAClD,CAAC;IAED,SAAS;QACL,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;IACxE,CAAC;IAED,KAAK;QACD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;IAED,aAAa,CAAC,GAAG;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,aAAa,CAAC,GAAG;QACb,IAAI,CAAC,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M,GAAG,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAExE,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;QACpD,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,MAAM,CAAC;QAClB,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAChF,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Real-time performance monitoring and metrics collection
|
|
3
3
|
*/
|
|
4
|
-
import { createCacheManager } from './cache-manager.js';
|
|
4
|
+
import { createCacheManager, cacheManager as globalCache } from './cache-manager.js';
|
|
5
5
|
// Create a dedicated cache instance for monitoring
|
|
6
6
|
const monitorCache = createCacheManager({
|
|
7
7
|
maxSize: 1000,
|
|
@@ -34,7 +34,7 @@ export class PerformanceMonitor {
|
|
|
34
34
|
const startTime = process.hrtime.bigint();
|
|
35
35
|
const startMemory = process.memoryUsage();
|
|
36
36
|
try {
|
|
37
|
-
const result = renderFn(component,
|
|
37
|
+
const result = renderFn(component, _props);
|
|
38
38
|
const endTime = process.hrtime.bigint();
|
|
39
39
|
const endMemory = process.memoryUsage();
|
|
40
40
|
const renderTimeMs = Number(endTime - startTime) / 1000000;
|
|
@@ -47,9 +47,9 @@ export class PerformanceMonitor {
|
|
|
47
47
|
});
|
|
48
48
|
return result;
|
|
49
49
|
}
|
|
50
|
-
catch (
|
|
51
|
-
this.recordError(
|
|
52
|
-
throw
|
|
50
|
+
catch (error) {
|
|
51
|
+
this.recordError(error, component);
|
|
52
|
+
throw error;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
recordRenderMetric(metric) {
|
|
@@ -65,11 +65,11 @@ export class PerformanceMonitor {
|
|
|
65
65
|
this.metrics.renderTimes = this.metrics.renderTimes.slice(-1000);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
recordError(
|
|
68
|
+
recordError(error, component) {
|
|
69
69
|
this.metrics.errors.push({
|
|
70
|
-
|
|
70
|
+
error: error.message,
|
|
71
71
|
component: this.getComponentName(component),
|
|
72
|
-
stack:
|
|
72
|
+
stack: error.stack,
|
|
73
73
|
timestamp: Date.now()
|
|
74
74
|
});
|
|
75
75
|
}
|
|
@@ -236,8 +236,8 @@ export class PerformanceMonitor {
|
|
|
236
236
|
if (errorRate > 5) {
|
|
237
237
|
recommendations.push({
|
|
238
238
|
priority: 'high',
|
|
239
|
-
issue: 'High
|
|
240
|
-
suggestion: 'Review component validation and
|
|
239
|
+
issue: 'High error rate',
|
|
240
|
+
suggestion: 'Review component validation and error handling',
|
|
241
241
|
impact: 'Improve stability and user experience'
|
|
242
242
|
});
|
|
243
243
|
}
|