Commit 7bcdcfd
committed
perf: Optimize vocabulary lookups with bitset-based implementation
Replace unordered_map-based Vocabularies with optimized bitset storage
for known JSON Schema vocabularies, providing significant performance
and memory improvements.
Implementation:
- Add Vocabularies struct with bitset storage for 29 known vocabularies
- Use std::bitset<29> for O(1) lookups vs hash map operations
- Maintain backward compatibility with unordered_map fallback for custom vocabularies
- Add Vocabularies::Known enum for type-safe vocabulary references
- Provide both string-based and enum-based APIs
API improvements:
- Add get() method returning optional<bool> (required/optional/not-found)
- Add contains() for checking required vocabularies only
- Add enum-based overloads for zero-overhead lookups
- Use initializer_list constructor for cleaner vocabulary creation
- Modern C++ with brace initialization
Performance gains:
- ~20-40x faster lookups for known vocabularies (bitset vs string hash)
- ~95% memory reduction (8 bytes vs ~1,448 bytes for 29 vocabularies)
- String lookups delegate to enum-based methods when possible
Test updates:
- Replace chained insert() calls with initializer lists
- Add combined vocabulary constants for common test scenarios
- Update all test macros to use new API (get() instead of at())
- Add vocabulary combinations: APPLICATOR_AND_VALIDATION, etc.
Files:
- src/core/jsonschema/vocabularies.cc: New implementation file
- src/core/jsonschema/include/sourcemeta/core/jsonschema_vocabularies.h: New header
- src/core/jsonschema/jsonschema_types.h: Remove typedef, use new class
- src/core/jsonschema/jsonschema.cc: Use initializer lists and enum API
- src/core/jsonschema/CMakeLists.txt: Add vocabularies.cc to build
TODO: Convert string-based vocabulary checks in alterschema rules,
bundle.cc, frame.cc, and official_walker.cc to use enum-based API for
additional performance gains (tracked in header comment).
Signed-off-by: Syed Azeez <syedazeez337@gmail.com>1 parent 38d686c commit 7bcdcfd
File tree
19 files changed
+416
-126
lines changed- src
- core/jsonschema
- include/sourcemeta/core
- extension/alterschema
- test/jsonschema
19 files changed
+416
-126
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
Lines changed: 7 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
| |||
Lines changed: 134 additions & 0 deletions
| 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 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
| 298 | + | |
| 299 | + | |
299 | 300 | | |
300 | 301 | | |
301 | | - | |
| 302 | + | |
302 | 303 | | |
303 | 304 | | |
304 | 305 | | |
305 | | - | |
| 306 | + | |
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
| |||
342 | 343 | | |
343 | 344 | | |
344 | 345 | | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
353 | 355 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
360 | 363 | | |
361 | 364 | | |
362 | 365 | | |
| |||
374 | 377 | | |
375 | 378 | | |
376 | 379 | | |
377 | | - | |
| 380 | + | |
378 | 381 | | |
379 | 382 | | |
380 | 383 | | |
| |||
394 | 397 | | |
395 | 398 | | |
396 | 399 | | |
397 | | - | |
| 400 | + | |
398 | 401 | | |
399 | 402 | | |
400 | 403 | | |
| |||
422 | 425 | | |
423 | 426 | | |
424 | 427 | | |
425 | | - | |
| 428 | + | |
426 | 429 | | |
427 | 430 | | |
428 | 431 | | |
429 | 432 | | |
430 | 433 | | |
431 | | - | |
| 434 | + | |
432 | 435 | | |
433 | 436 | | |
434 | | - | |
| 437 | + | |
435 | 438 | | |
436 | 439 | | |
437 | 440 | | |
438 | 441 | | |
439 | 442 | | |
440 | 443 | | |
441 | | - | |
442 | | - | |
443 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
444 | 450 | | |
445 | 451 | | |
446 | 452 | | |
| |||
0 commit comments