@fjell/registry 4.4.5 → 4.4.7

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.
Files changed (52) hide show
  1. package/README.md +546 -0
  2. package/dist/Coordinate.cjs +8 -5
  3. package/dist/Coordinate.d.ts +1 -1
  4. package/dist/Coordinate.js +8 -5
  5. package/dist/Instance.cjs +1 -1
  6. package/dist/Instance.d.ts +1 -1
  7. package/dist/Instance.js +1 -1
  8. package/dist/Registry.cjs +99 -90
  9. package/dist/Registry.d.ts +3 -42
  10. package/dist/Registry.js +99 -90
  11. package/dist/RegistryHub.cjs +78 -0
  12. package/dist/RegistryHub.d.ts +3 -0
  13. package/dist/RegistryHub.js +74 -0
  14. package/dist/errors/CoordinateError.cjs +70 -0
  15. package/dist/errors/CoordinateError.d.ts +28 -0
  16. package/dist/errors/CoordinateError.js +63 -0
  17. package/dist/errors/InstanceError.cjs +101 -0
  18. package/dist/errors/InstanceError.d.ts +42 -0
  19. package/dist/errors/InstanceError.js +92 -0
  20. package/dist/errors/RegistryError.cjs +82 -0
  21. package/dist/errors/RegistryError.d.ts +31 -0
  22. package/dist/errors/RegistryError.js +75 -0
  23. package/dist/errors/RegistryHubError.cjs +92 -0
  24. package/dist/errors/RegistryHubError.d.ts +39 -0
  25. package/dist/errors/RegistryHubError.js +84 -0
  26. package/dist/errors/index.d.ts +4 -0
  27. package/dist/index.cjs +501 -101
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +3 -0
  30. package/dist/index.js +6 -1
  31. package/dist/types.d.ts +90 -0
  32. package/docs/TIMING_NODE_OPTIMIZATION.md +207 -0
  33. package/docs/TIMING_README.md +170 -0
  34. package/docs/memory-data/scaling-10-instances.json +526 -0
  35. package/docs/memory-data/scaling-100-instances.json +526 -0
  36. package/docs/memory-data/scaling-1000-instances.json +276 -0
  37. package/docs/memory-data/scaling-10000-instances.json +126 -0
  38. package/docs/memory-data/scaling-20-instances.json +526 -0
  39. package/docs/memory-data/scaling-200-instances.json +526 -0
  40. package/docs/memory-data/scaling-2000-instances.json +276 -0
  41. package/docs/memory-data/scaling-50-instances.json +526 -0
  42. package/docs/memory-data/scaling-500-instances.json +276 -0
  43. package/docs/memory-data/scaling-5000-instances.json +126 -0
  44. package/docs/memory-overhead.svg +120 -0
  45. package/docs/memory.md +430 -0
  46. package/docs/timing-range.svg +174 -0
  47. package/docs/timing.md +483 -0
  48. package/examples/README.md +187 -0
  49. package/examples/multi-level-keys.ts +374 -0
  50. package/examples/registry-hub-types.ts +437 -0
  51. package/examples/simple-example.ts +250 -0
  52. package/package.json +6 -4
package/docs/timing.md ADDED
@@ -0,0 +1,483 @@
1
+ # Performance Timing Report
2
+
3
+ Generated: 2025-07-19T19:08:20.231Z
4
+ Version: 4.4.5
5
+ Node.js: v22.0.0
6
+ Platform: darwin arm64
7
+
8
+ ## Summary
9
+
10
+ This document contains performance timing metrics for key operations in @fjell/registry.
11
+ All measurements are taken over 200 iterations (unless otherwise noted) with warm-up runs.
12
+ Timing results are reported in microseconds (µs) for precision.
13
+
14
+ ## Basic Operations Performance
15
+
16
+ | Operation | Description | Avg Time (µs) | Min Time (µs) | Max Time (µs) | Threshold (µs) | Status |
17
+ |-----------|-------------|---------------|---------------|---------------|----------------|--------|
18
+ | createRegistry | Time to create a new registry | 0.2 | 0.0 | 865.0 | 5000 | ✅ PASS |
19
+ | createRegistryHub | Time to create a new registry hub | 0.1 | 0.0 | 395.9 | 5000 | ✅ PASS |
20
+ | createInstance | Time to create a new instance | 1.0 | 0.2 | 3362.4 | 10000 | ✅ PASS |
21
+ | registerInstance | Time to register an instance in registry | 6.0 | 0.7 | 14657.3 | 5000 | ✅ PASS |
22
+ | lookupInstance | Time to lookup an existing instance from registry | 0.3 | 0.0 | 685.2 | 2000 | ✅ PASS |
23
+ | completeWorkflow | Time for complete workflow: create hub, registry, instance, register, and lookup | 6.4 | 2.1 | 7064.8 | 25000 | ✅ PASS |
24
+
25
+ ## Scaling Performance Tests
26
+
27
+ | Operation | Tree Size | Avg Time (µs) | Min Time (µs) | Max Time (µs) | Threshold (µs) | Status |
28
+ |-----------|-----------|---------------|---------------|---------------|----------------|--------|
29
+ | registerInstance_10 | 10 | 2.9 | 0.8 | 8043.9 | 5000 | ✅ PASS |
30
+ | lookupInstance_10 | 10 | 0.2 | 0.0 | 57.5 | 2000 | ✅ PASS |
31
+ | registerInstance_20 | 20 | 4.0 | 0.8 | 5138.1 | 5000 | ✅ PASS |
32
+ | lookupInstance_20 | 20 | 0.4 | 0.0 | 2896.7 | 2000 | ✅ PASS |
33
+ | registerInstance_50 | 50 | 1.8 | 0.7 | 3538.8 | 5000 | ✅ PASS |
34
+ | lookupInstance_50 | 50 | 0.2 | 0.0 | 17.3 | 2000 | ✅ PASS |
35
+ | registerInstance_100 | 100 | 3.0 | 0.8 | 3714.0 | 5000 | ✅ PASS |
36
+ | lookupInstance_100 | 100 | 0.3 | 0.0 | 2029.2 | 2000 | ✅ PASS |
37
+ | registerInstance_200 | 200 | 1.6 | 0.8 | 2891.4 | 10000 | ✅ PASS |
38
+ | lookupInstance_200 | 200 | 0.3 | 0.0 | 2867.3 | 5000 | ✅ PASS |
39
+ | registerInstance_500 | 500 | 1.5 | 0.7 | 3092.2 | 10000 | ✅ PASS |
40
+ | lookupInstance_500 | 500 | 0.3 | 0.0 | 3657.6 | 5000 | ✅ PASS |
41
+ | registerInstance_1000 | 1000 | 1.6 | 0.7 | 4527.8 | 10000 | ✅ PASS |
42
+ | lookupInstance_1000 | 1000 | 0.2 | 0.0 | 2594.0 | 5000 | ✅ PASS |
43
+ | registerInstance_2000 | 2000 | 1.1 | 0.8 | 63.3 | 20000 | ✅ PASS |
44
+ | lookupInstance_2000 | 2000 | 0.2 | 0.0 | 8.2 | 10000 | ✅ PASS |
45
+ | registerInstance_5000 | 5000 | 1.7 | 1.1 | 291.6 | 20000 | ✅ PASS |
46
+ | lookupInstance_5000 | 5000 | 1.8 | 0.0 | 7794.5 | 10000 | ✅ PASS |
47
+ | registerInstance_10000 | 10000 | 4.7 | 1.1 | 4041.7 | 20000 | ✅ PASS |
48
+ | lookupInstance_10000 | 10000 | 0.3 | 0.0 | 46.0 | 10000 | ✅ PASS |
49
+ | registerInstance_20000 | 20000 | 1.2 | 0.9 | 5.8 | 50000 | ✅ PASS |
50
+ | lookupInstance_20000 | 20000 | 0.3 | 0.1 | 4.8 | 25000 | ✅ PASS |
51
+ | registerInstance_50000 | 50000 | 1.2 | 0.9 | 18.1 | 50000 | ✅ PASS |
52
+ | lookupInstance_50000 | 50000 | 0.2 | 0.1 | 3.4 | 25000 | ✅ PASS |
53
+ | registerInstance_100000 | 100000 | 1.3 | 0.9 | 31.5 | 50000 | ✅ PASS |
54
+ | lookupInstance_100000 | 100000 | 0.2 | 0.1 | 5.2 | 25000 | ✅ PASS |
55
+
56
+ ## Scaling Performance Visualization
57
+
58
+ ### Performance Range Chart
59
+ ![Performance Range Chart](./timing-range.svg)
60
+
61
+ *This performance range chart shows the average performance (center line) with ±1 standard deviation bands for each tree size.
62
+ The bands reveal performance consistency and variability across 100 test rounds. Tight bands indicate
63
+ consistent performance, while wider bands show more variability.*
64
+
65
+
66
+ ## Detailed Results
67
+
68
+ ### Basic Operations
69
+
70
+ #### createRegistry
71
+
72
+ **Description:** Time to create a new registry
73
+ **Iterations:** 20000
74
+ **Average Time:** 0.2 µs
75
+ **Min Time:** 0.0 µs
76
+ **Max Time:** 865.0 µs
77
+ **Threshold:** 5000 µs
78
+ **Status:** ✅ PASS
79
+
80
+ #### createRegistryHub
81
+
82
+ **Description:** Time to create a new registry hub
83
+ **Iterations:** 20000
84
+ **Average Time:** 0.1 µs
85
+ **Min Time:** 0.0 µs
86
+ **Max Time:** 395.9 µs
87
+ **Threshold:** 5000 µs
88
+ **Status:** ✅ PASS
89
+
90
+ #### createInstance
91
+
92
+ **Description:** Time to create a new instance
93
+ **Iterations:** 20000
94
+ **Average Time:** 1.0 µs
95
+ **Min Time:** 0.2 µs
96
+ **Max Time:** 3362.4 µs
97
+ **Threshold:** 10000 µs
98
+ **Status:** ✅ PASS
99
+
100
+ #### registerInstance
101
+
102
+ **Description:** Time to register an instance in registry
103
+ **Iterations:** 20000
104
+ **Average Time:** 6.0 µs
105
+ **Min Time:** 0.7 µs
106
+ **Max Time:** 14657.3 µs
107
+ **Threshold:** 5000 µs
108
+ **Status:** ✅ PASS
109
+
110
+ #### lookupInstance
111
+
112
+ **Description:** Time to lookup an existing instance from registry
113
+ **Iterations:** 20000
114
+ **Average Time:** 0.3 µs
115
+ **Min Time:** 0.0 µs
116
+ **Max Time:** 685.2 µs
117
+ **Threshold:** 2000 µs
118
+ **Status:** ✅ PASS
119
+
120
+ #### completeWorkflow
121
+
122
+ **Description:** Time for complete workflow: create hub, registry, instance, register, and lookup
123
+ **Iterations:** 10000
124
+ **Average Time:** 6.4 µs
125
+ **Min Time:** 2.1 µs
126
+ **Max Time:** 7064.8 µs
127
+ **Threshold:** 25000 µs
128
+ **Status:** ✅ PASS
129
+
130
+ ### Scaling Tests
131
+
132
+ #### registerInstance_10 (Tree Size: 10)
133
+
134
+ **Description:** Time to register instance with 10 existing items in tree
135
+ **Tree Size:** 10 items
136
+ **Iterations:** 10000
137
+ **Average Time:** 2.9 µs
138
+ **Min Time:** 0.8 µs
139
+ **Max Time:** 8043.9 µs
140
+ **Threshold:** 5000 µs
141
+ **Status:** ✅ PASS
142
+
143
+ #### lookupInstance_10 (Tree Size: 10)
144
+
145
+ **Description:** Time to lookup instance with 10 items in tree
146
+ **Tree Size:** 10 items
147
+ **Iterations:** 20000
148
+ **Average Time:** 0.2 µs
149
+ **Min Time:** 0.0 µs
150
+ **Max Time:** 57.5 µs
151
+ **Threshold:** 2000 µs
152
+ **Status:** ✅ PASS
153
+
154
+ #### registerInstance_20 (Tree Size: 20)
155
+
156
+ **Description:** Time to register instance with 20 existing items in tree
157
+ **Tree Size:** 20 items
158
+ **Iterations:** 10000
159
+ **Average Time:** 4.0 µs
160
+ **Min Time:** 0.8 µs
161
+ **Max Time:** 5138.1 µs
162
+ **Threshold:** 5000 µs
163
+ **Status:** ✅ PASS
164
+
165
+ #### lookupInstance_20 (Tree Size: 20)
166
+
167
+ **Description:** Time to lookup instance with 20 items in tree
168
+ **Tree Size:** 20 items
169
+ **Iterations:** 20000
170
+ **Average Time:** 0.4 µs
171
+ **Min Time:** 0.0 µs
172
+ **Max Time:** 2896.7 µs
173
+ **Threshold:** 2000 µs
174
+ **Status:** ✅ PASS
175
+
176
+ #### registerInstance_50 (Tree Size: 50)
177
+
178
+ **Description:** Time to register instance with 50 existing items in tree
179
+ **Tree Size:** 50 items
180
+ **Iterations:** 10000
181
+ **Average Time:** 1.8 µs
182
+ **Min Time:** 0.7 µs
183
+ **Max Time:** 3538.8 µs
184
+ **Threshold:** 5000 µs
185
+ **Status:** ✅ PASS
186
+
187
+ #### lookupInstance_50 (Tree Size: 50)
188
+
189
+ **Description:** Time to lookup instance with 50 items in tree
190
+ **Tree Size:** 50 items
191
+ **Iterations:** 20000
192
+ **Average Time:** 0.2 µs
193
+ **Min Time:** 0.0 µs
194
+ **Max Time:** 17.3 µs
195
+ **Threshold:** 2000 µs
196
+ **Status:** ✅ PASS
197
+
198
+ #### registerInstance_100 (Tree Size: 100)
199
+
200
+ **Description:** Time to register instance with 100 existing items in tree
201
+ **Tree Size:** 100 items
202
+ **Iterations:** 10000
203
+ **Average Time:** 3.0 µs
204
+ **Min Time:** 0.8 µs
205
+ **Max Time:** 3714.0 µs
206
+ **Threshold:** 5000 µs
207
+ **Status:** ✅ PASS
208
+
209
+ #### lookupInstance_100 (Tree Size: 100)
210
+
211
+ **Description:** Time to lookup instance with 100 items in tree
212
+ **Tree Size:** 100 items
213
+ **Iterations:** 20000
214
+ **Average Time:** 0.3 µs
215
+ **Min Time:** 0.0 µs
216
+ **Max Time:** 2029.2 µs
217
+ **Threshold:** 2000 µs
218
+ **Status:** ✅ PASS
219
+
220
+ #### registerInstance_200 (Tree Size: 200)
221
+
222
+ **Description:** Time to register instance with 200 existing items in tree
223
+ **Tree Size:** 200 items
224
+ **Iterations:** 10000
225
+ **Average Time:** 1.6 µs
226
+ **Min Time:** 0.8 µs
227
+ **Max Time:** 2891.4 µs
228
+ **Threshold:** 10000 µs
229
+ **Status:** ✅ PASS
230
+
231
+ #### lookupInstance_200 (Tree Size: 200)
232
+
233
+ **Description:** Time to lookup instance with 200 items in tree
234
+ **Tree Size:** 200 items
235
+ **Iterations:** 20000
236
+ **Average Time:** 0.3 µs
237
+ **Min Time:** 0.0 µs
238
+ **Max Time:** 2867.3 µs
239
+ **Threshold:** 5000 µs
240
+ **Status:** ✅ PASS
241
+
242
+ #### registerInstance_500 (Tree Size: 500)
243
+
244
+ **Description:** Time to register instance with 500 existing items in tree
245
+ **Tree Size:** 500 items
246
+ **Iterations:** 10000
247
+ **Average Time:** 1.5 µs
248
+ **Min Time:** 0.7 µs
249
+ **Max Time:** 3092.2 µs
250
+ **Threshold:** 10000 µs
251
+ **Status:** ✅ PASS
252
+
253
+ #### lookupInstance_500 (Tree Size: 500)
254
+
255
+ **Description:** Time to lookup instance with 500 items in tree
256
+ **Tree Size:** 500 items
257
+ **Iterations:** 20000
258
+ **Average Time:** 0.3 µs
259
+ **Min Time:** 0.0 µs
260
+ **Max Time:** 3657.6 µs
261
+ **Threshold:** 5000 µs
262
+ **Status:** ✅ PASS
263
+
264
+ #### registerInstance_1000 (Tree Size: 1000)
265
+
266
+ **Description:** Time to register instance with 1000 existing items in tree
267
+ **Tree Size:** 1000 items
268
+ **Iterations:** 10000
269
+ **Average Time:** 1.6 µs
270
+ **Min Time:** 0.7 µs
271
+ **Max Time:** 4527.8 µs
272
+ **Threshold:** 10000 µs
273
+ **Status:** ✅ PASS
274
+
275
+ #### lookupInstance_1000 (Tree Size: 1000)
276
+
277
+ **Description:** Time to lookup instance with 1000 items in tree
278
+ **Tree Size:** 1000 items
279
+ **Iterations:** 20000
280
+ **Average Time:** 0.2 µs
281
+ **Min Time:** 0.0 µs
282
+ **Max Time:** 2594.0 µs
283
+ **Threshold:** 5000 µs
284
+ **Status:** ✅ PASS
285
+
286
+ #### registerInstance_2000 (Tree Size: 2000)
287
+
288
+ **Description:** Time to register instance with 2000 existing items in tree
289
+ **Tree Size:** 2000 items
290
+ **Iterations:** 2500
291
+ **Average Time:** 1.1 µs
292
+ **Min Time:** 0.8 µs
293
+ **Max Time:** 63.3 µs
294
+ **Threshold:** 20000 µs
295
+ **Status:** ✅ PASS
296
+
297
+ #### lookupInstance_2000 (Tree Size: 2000)
298
+
299
+ **Description:** Time to lookup instance with 2000 items in tree
300
+ **Tree Size:** 2000 items
301
+ **Iterations:** 5000
302
+ **Average Time:** 0.2 µs
303
+ **Min Time:** 0.0 µs
304
+ **Max Time:** 8.2 µs
305
+ **Threshold:** 10000 µs
306
+ **Status:** ✅ PASS
307
+
308
+ #### registerInstance_5000 (Tree Size: 5000)
309
+
310
+ **Description:** Time to register instance with 5000 existing items in tree
311
+ **Tree Size:** 5000 items
312
+ **Iterations:** 2500
313
+ **Average Time:** 1.7 µs
314
+ **Min Time:** 1.1 µs
315
+ **Max Time:** 291.6 µs
316
+ **Threshold:** 20000 µs
317
+ **Status:** ✅ PASS
318
+
319
+ #### lookupInstance_5000 (Tree Size: 5000)
320
+
321
+ **Description:** Time to lookup instance with 5000 items in tree
322
+ **Tree Size:** 5000 items
323
+ **Iterations:** 5000
324
+ **Average Time:** 1.8 µs
325
+ **Min Time:** 0.0 µs
326
+ **Max Time:** 7794.5 µs
327
+ **Threshold:** 10000 µs
328
+ **Status:** ✅ PASS
329
+
330
+ #### registerInstance_10000 (Tree Size: 10000)
331
+
332
+ **Description:** Time to register instance with 10000 existing items in tree
333
+ **Tree Size:** 10000 items
334
+ **Iterations:** 2500
335
+ **Average Time:** 4.7 µs
336
+ **Min Time:** 1.1 µs
337
+ **Max Time:** 4041.7 µs
338
+ **Threshold:** 20000 µs
339
+ **Status:** ✅ PASS
340
+
341
+ #### lookupInstance_10000 (Tree Size: 10000)
342
+
343
+ **Description:** Time to lookup instance with 10000 items in tree
344
+ **Tree Size:** 10000 items
345
+ **Iterations:** 5000
346
+ **Average Time:** 0.3 µs
347
+ **Min Time:** 0.0 µs
348
+ **Max Time:** 46.0 µs
349
+ **Threshold:** 10000 µs
350
+ **Status:** ✅ PASS
351
+
352
+ #### registerInstance_20000 (Tree Size: 20000)
353
+
354
+ **Description:** Time to register instance with 20000 existing items in tree
355
+ **Tree Size:** 20000 items
356
+ **Iterations:** 500
357
+ **Average Time:** 1.2 µs
358
+ **Min Time:** 0.9 µs
359
+ **Max Time:** 5.8 µs
360
+ **Threshold:** 50000 µs
361
+ **Status:** ✅ PASS
362
+
363
+ #### lookupInstance_20000 (Tree Size: 20000)
364
+
365
+ **Description:** Time to lookup instance with 20000 items in tree
366
+ **Tree Size:** 20000 items
367
+ **Iterations:** 1250
368
+ **Average Time:** 0.3 µs
369
+ **Min Time:** 0.1 µs
370
+ **Max Time:** 4.8 µs
371
+ **Threshold:** 25000 µs
372
+ **Status:** ✅ PASS
373
+
374
+ #### registerInstance_50000 (Tree Size: 50000)
375
+
376
+ **Description:** Time to register instance with 50000 existing items in tree
377
+ **Tree Size:** 50000 items
378
+ **Iterations:** 500
379
+ **Average Time:** 1.2 µs
380
+ **Min Time:** 0.9 µs
381
+ **Max Time:** 18.1 µs
382
+ **Threshold:** 50000 µs
383
+ **Status:** ✅ PASS
384
+
385
+ #### lookupInstance_50000 (Tree Size: 50000)
386
+
387
+ **Description:** Time to lookup instance with 50000 items in tree
388
+ **Tree Size:** 50000 items
389
+ **Iterations:** 1250
390
+ **Average Time:** 0.2 µs
391
+ **Min Time:** 0.1 µs
392
+ **Max Time:** 3.4 µs
393
+ **Threshold:** 25000 µs
394
+ **Status:** ✅ PASS
395
+
396
+ #### registerInstance_100000 (Tree Size: 100000)
397
+
398
+ **Description:** Time to register instance with 100000 existing items in tree
399
+ **Tree Size:** 100000 items
400
+ **Iterations:** 500
401
+ **Average Time:** 1.3 µs
402
+ **Min Time:** 0.9 µs
403
+ **Max Time:** 31.5 µs
404
+ **Threshold:** 50000 µs
405
+ **Status:** ✅ PASS
406
+
407
+ #### lookupInstance_100000 (Tree Size: 100000)
408
+
409
+ **Description:** Time to lookup instance with 100000 items in tree
410
+ **Tree Size:** 100000 items
411
+ **Iterations:** 1250
412
+ **Average Time:** 0.2 µs
413
+ **Min Time:** 0.1 µs
414
+ **Max Time:** 5.2 µs
415
+ **Threshold:** 25000 µs
416
+ **Status:** ✅ PASS
417
+
418
+ ## Performance Analysis
419
+
420
+ ### Key Metrics
421
+
422
+ - **Registry Creation**: Fast lightweight object creation
423
+ - **RegistryHub Creation**: Minimal overhead for hub management
424
+ - **Instance Creation**: Efficient coordinate-based instance creation
425
+ - **Instance Lookup**: Optimized tree traversal for instance retrieval
426
+ - **Registration**: Quick instance registration with scope support
427
+
428
+ ### Scaling Analysis
429
+
430
+ The scaling tests measure performance across a wide range of tree sizes to identify potential O(n) issues:
431
+
432
+ - **Small Scale (10-100)**: Baseline performance for small registries
433
+ - **Medium Scale (200-1000)**: Standard application-scale registry performance
434
+ - **Large Scale (2000-10000)**: Enterprise-scale registry performance
435
+ - **Very Large Scale (20000-100000)**: Extreme-scale registry stress testing
436
+
437
+ Tree sizes tested: 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000
438
+
439
+ These comprehensive tests help ensure that the registry maintains good performance characteristics across all
440
+ deployment scenarios, from small applications to large-scale enterprise systems.
441
+
442
+ ### Timing Constraints
443
+
444
+ The following timing constraints are enforced to ensure optimal performance:
445
+
446
+ #### Basic Operations
447
+ - **createRegistry**: ≤ 5000µs (5.0ms)
448
+ - **createRegistryHub**: ≤ 5000µs (5.0ms)
449
+ - **createInstance**: ≤ 10000µs (10.0ms)
450
+ - **lookupInstance**: ≤ 2000µs (2.0ms)
451
+ - **registerInstance**: ≤ 5000µs (5.0ms)
452
+
453
+ #### Scaling Operations
454
+ - **registerInstance** (≤100 items): ≤ 5000µs (5ms)
455
+ - **registerInstance** (100-1000 items): ≤ 10000µs (10ms)
456
+ - **registerInstance** (1000-10000 items): ≤ 20000µs (20ms)
457
+ - **registerInstance** (>10000 items): ≤ 50000µs (50ms)
458
+ - **lookupInstance** (≤100 items): ≤ 2000µs (2ms)
459
+ - **lookupInstance** (100-1000 items): ≤ 5000µs (5ms)
460
+ - **lookupInstance** (1000-10000 items): ≤ 10000µs (10ms)
461
+ - **lookupInstance** (>10000 items): ≤ 25000µs (25ms)
462
+
463
+ ### Notes
464
+
465
+ - All timing tests include warm-up iterations to account for JIT compilation
466
+ - Tests are run in isolation to minimize interference
467
+ - Results may vary based on system specifications and current load
468
+ - Timing results are reported in microseconds (µs) for precision
469
+ - Timing constraints are set to ensure the library performs well in production environments
470
+ - Scaling tests help identify performance degradation as registry size increases
471
+
472
+ ### Recommendations
473
+
474
+ If any timing tests fail:
475
+
476
+ 1. **Review Recent Changes**: Check if recent code changes have introduced performance regressions
477
+ 2. **System Resources**: Ensure adequate system resources are available during testing
478
+ 3. **Optimization**: Consider optimizing the failing operations if thresholds are consistently exceeded
479
+ 4. **Threshold Review**: Review if timing constraints are still appropriate for current use cases
480
+
481
+ ---
482
+
483
+ *This document is automatically generated during testing and should be updated with each release.*
@@ -0,0 +1,187 @@
1
+ # Registry Examples
2
+
3
+ This directory contains examples demonstrating how to use the Registry with different key patterns and configurations.
4
+
5
+ ## Examples
6
+
7
+ ### 1. `simple-example.ts` ⭐ **Start Here!**
8
+ **Perfect for beginners!** Demonstrates the simplest possible way to use the Registry:
9
+ - **No RegistryHub required** - just call `createRegistry()`
10
+ - **No scopes needed** - pass empty array `[]` or omit entirely
11
+ - **Basic dependency injection** - register and retrieve services
12
+ - **Service dependencies** - shows how services can depend on each other
13
+
14
+ Great for simple applications that just need basic dependency injection without complexity.
15
+
16
+ ### 2. `multi-level-keys.ts`
17
+ **Advanced usage with scopes and multi-level keys!** Demonstrates how Registry supports hierarchical key type arrays:
18
+ - **Single level**: `['user']`, `['task']` - SQL vs NoSQL implementations
19
+ - **Two levels**: `['user', 'profile']` - S3 vs Local storage implementations
20
+ - **Three levels**: `['user', 'profile', 'preference']` - Redis implementation
21
+ - **Real scopes**: Production vs development environments
22
+ - **Multiple implementations**: Same interface, different backends
23
+
24
+ Shows how each key path maps to different implementations via scopes using the real library.
25
+
26
+ ### 3. `registry-hub-types.ts` 🏗️ **Enterprise Architecture**
27
+ **Large-scale application with service organization!** Demonstrates how RegistryHub manages multiple registries for different service types:
28
+ - **Service Categories**: Business logic, data access, infrastructure, communication
29
+ - **Type-based Organization**: Services organized by purpose and responsibility
30
+ - **Cross-Registry Workflows**: Services from different registries working together
31
+ - **Environment Configuration**: Production vs development implementations
32
+ - **Centralized Discovery**: Single hub for all service types
33
+
34
+ Perfect for enterprise applications that need clean separation of concerns and organized service architecture.
35
+
36
+ ## Key Concepts Demonstrated
37
+
38
+ ### Simple Usage (simple-example.ts)
39
+ ```typescript
40
+ // Import the real registry functionality
41
+ import { createRegistry, createInstance } from '../src/Registry';
42
+
43
+ // Create a registry - no RegistryHub needed!
44
+ const registry = createRegistry('app');
45
+
46
+ // Register a service - no scopes needed!
47
+ registry.createInstance(['logger'], [], (coordinate, context) => {
48
+ const service = new LoggerService();
49
+ const instance = createInstance(context.registry, coordinate);
50
+ (instance as any).log = service.log.bind(service);
51
+ return instance;
52
+ });
53
+
54
+ // Get the service - no scopes needed!
55
+ const logger = registry.get(['logger']);
56
+ logger.log('Hello from the registry!');
57
+ ```
58
+
59
+ ### Multi-Level Key Arrays
60
+ ```typescript
61
+ // Different key path levels
62
+ ['user'] // → UserService implementation
63
+ ['user', 'profile'] // → UserProfileService implementation
64
+ ['user', 'profile', 'preference'] // → UserPreferenceService implementation
65
+ ['task'] // → TaskService implementation
66
+ ```
67
+
68
+ ### RegistryHub Usage (registry-hub-types.ts)
69
+ ```typescript
70
+ // Import RegistryHub functionality
71
+ import { createRegistryHub } from '../src/RegistryHub';
72
+ import { createRegistry } from '../src/Registry';
73
+
74
+ // Create a hub to manage multiple registries
75
+ const hub = createRegistryHub();
76
+
77
+ // Create specialized registries for different service types
78
+ const servicesRegistry = createRegistry('services'); // Business logic
79
+ const dataRegistry = createRegistry('data'); // Data access
80
+ const infraRegistry = createRegistry('infrastructure'); // Infrastructure
81
+ const commRegistry = createRegistry('communication'); // External services
82
+
83
+ // Register all registries in the hub
84
+ hub.registerRegistry(servicesRegistry);
85
+ hub.registerRegistry(dataRegistry);
86
+ hub.registerRegistry(infraRegistry);
87
+ hub.registerRegistry(commRegistry);
88
+
89
+ // Register services by type and scope
90
+ servicesRegistry.createInstance(['auth'], ['prod'], (coordinate, context) => {
91
+ // JWT implementation for production
92
+ });
93
+
94
+ dataRegistry.createInstance(['user'], ['sql'], (coordinate, context) => {
95
+ // PostgreSQL implementation
96
+ });
97
+
98
+ // Retrieve services by type and scope through the hub
99
+ const prodAuth = hub.get('services', ['auth'], { scopes: ['prod'] });
100
+ const sqlUser = hub.get('data', ['user'], { scopes: ['sql'] });
101
+ const cache = hub.get('infrastructure', ['cache'], { scopes: ['dev'] });
102
+ const email = hub.get('communication', ['email'], { scopes: ['prod'] });
103
+ ```
104
+
105
+ ### Scope-Based Implementation Selection
106
+ - Multiple implementations per key path
107
+ - Runtime selection via scopes
108
+ - Environment-based switching (prod/dev/test)
109
+ - Feature flags and A/B testing support
110
+
111
+ ### Real-World Use Cases
112
+ - **Database Abstraction**: Different implementations for PostgreSQL, MongoDB, etc.
113
+ - **Environment Selection**: Different implementations for prod/dev
114
+ - **Testing**: Mock implementations with 'test' scope
115
+ - **Microservices**: Each key path represents a different service
116
+ - **Multi-Region**: Different implementations across regions
117
+
118
+ ## Running Examples
119
+
120
+ ```bash
121
+ # Start with the simple example (recommended)
122
+ npx tsx examples/simple-example.ts
123
+
124
+ # Run the multi-level keys example
125
+ npx tsx examples/multi-level-keys.ts
126
+
127
+ # Run the RegistryHub with service types example
128
+ npx tsx examples/registry-hub-types.ts
129
+
130
+ # Or in Node.js
131
+ node -r esbuild-register examples/simple-example.ts
132
+ node -r esbuild-register examples/registry-hub-types.ts
133
+ ```
134
+
135
+ ## Integration with Real Fjell Registry
136
+
137
+ Both examples now use the real library! In actual usage with the built package:
138
+
139
+ ```typescript
140
+ import { createRegistry, createInstance } from '@fjell/registry';
141
+
142
+ // Simple usage - no RegistryHub, no scopes
143
+ const registry = createRegistry('app');
144
+
145
+ registry.createInstance(['user'], [], (coordinate, context) => {
146
+ const service = new UserService();
147
+ const instance = createInstance(context.registry, coordinate);
148
+ (instance as any).save = service.save.bind(service);
149
+ return instance;
150
+ });
151
+
152
+ const user = registry.get(['user']);
153
+
154
+ // Advanced usage - with scopes for multiple implementations
155
+ registry.createInstance(['user'], ['sql', 'prod'], (coordinate, context) => {
156
+ const service = new SqlUserService();
157
+ const instance = createInstance(context.registry, coordinate);
158
+ (instance as any).save = service.save.bind(service);
159
+ return instance;
160
+ });
161
+
162
+ const prodUser = registry.get(['user'], { scopes: ['prod'] });
163
+ ```
164
+
165
+ ## When to Use What
166
+
167
+ **Use `simple-example.ts` approach when:**
168
+ - You're just getting started
169
+ - You have a simple application
170
+ - You don't need multiple implementations per service
171
+ - You want basic dependency injection
172
+
173
+ **Use `multi-level-keys.ts` approach when:**
174
+ - You need multiple implementations (prod/dev/test)
175
+ - You have complex service hierarchies
176
+ - You need environment-based switching
177
+ - You're building a large, complex application
178
+
179
+ **Use `registry-hub-types.ts` approach when:**
180
+ - You're building enterprise-scale applications
181
+ - You need to organize services by type/category
182
+ - You have multiple teams working on different service layers
183
+ - You want clean separation between business logic, data, and infrastructure
184
+ - You need centralized service discovery across service types
185
+ - You're implementing microservices or modular architecture
186
+
187
+ This approach provides the foundation for the Fjell library's architecture pattern with swappable implementations and enterprise-scale service organization.