@atomic-ehr/fhirpath 0.0.1-canary.0c6931e.20250727185306
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/README.md +473 -0
- package/dist/index.d.ts +462 -0
- package/dist/index.js +10307 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
- package/src/analyzer/analyzer.ts +499 -0
- package/src/analyzer/model-provider.ts +244 -0
- package/src/analyzer/schemas/index.ts +2 -0
- package/src/analyzer/schemas/types.ts +40 -0
- package/src/analyzer/types.ts +142 -0
- package/src/api/builder.ts +157 -0
- package/src/api/errors.ts +145 -0
- package/src/api/expression.ts +156 -0
- package/src/api/index.ts +122 -0
- package/src/api/inspect.ts +99 -0
- package/src/api/registry.ts +128 -0
- package/src/api/types.ts +210 -0
- package/src/compiler/compiler.ts +546 -0
- package/src/compiler/index.ts +2 -0
- package/src/compiler/prototype-context-adapter.ts +99 -0
- package/src/compiler/types.ts +24 -0
- package/src/index.ts +107 -0
- package/src/interpreter/README.md +78 -0
- package/src/interpreter/interpreter.ts +475 -0
- package/src/interpreter/types.ts +108 -0
- package/src/lexer/char-tables.ts +37 -0
- package/src/lexer/errors.ts +31 -0
- package/src/lexer/index.ts +5 -0
- package/src/lexer/lexer.ts +745 -0
- package/src/lexer/token.ts +104 -0
- package/src/lexer2/index.md +232 -0
- package/src/lexer2/index.perf.test.ts +68 -0
- package/src/lexer2/index.test.ts +549 -0
- package/src/lexer2/index.ts +1251 -0
- package/src/lexer2/notes.md +173 -0
- package/src/lexer2/optimization-summary.md +718 -0
- package/src/parser/ast-factory.ts +220 -0
- package/src/parser/ast.ts +144 -0
- package/src/parser/collection-parser.ts +89 -0
- package/src/parser/diagnostic-messages.ts +216 -0
- package/src/parser/diagnostics.ts +85 -0
- package/src/parser/error-reporter.ts +230 -0
- package/src/parser/index.ts +3 -0
- package/src/parser/literal-parser.ts +103 -0
- package/src/parser/parse-error.ts +16 -0
- package/src/parser/parser-error-factory.ts +141 -0
- package/src/parser/parser-state.ts +134 -0
- package/src/parser/parser.ts +1272 -0
- package/src/parser/pprint.ts +169 -0
- package/src/parser/precedence-manager.ts +64 -0
- package/src/parser/source-mapper.ts +248 -0
- package/src/parser/special-constructs.ts +142 -0
- package/src/parser/token-navigator.ts +110 -0
- package/src/parser/types.ts +60 -0
- package/src/parser2/index.md +177 -0
- package/src/parser2/index.perf.test.ts +184 -0
- package/src/parser2/index.test.ts +305 -0
- package/src/parser2/index.ts +578 -0
- package/src/parser2/optimization-summary.md +176 -0
- package/src/registry/default-analyzers.ts +257 -0
- package/src/registry/default-compilers.ts +31 -0
- package/src/registry/index.ts +96 -0
- package/src/registry/operations/arithmetic.ts +506 -0
- package/src/registry/operations/collection.ts +425 -0
- package/src/registry/operations/comparison.ts +432 -0
- package/src/registry/operations/existence.ts +703 -0
- package/src/registry/operations/filtering.ts +358 -0
- package/src/registry/operations/literals.ts +341 -0
- package/src/registry/operations/logical.ts +439 -0
- package/src/registry/operations/math.ts +128 -0
- package/src/registry/operations/membership.ts +132 -0
- package/src/registry/operations/navigation.ts +52 -0
- package/src/registry/operations/string.ts +507 -0
- package/src/registry/operations/subsetting.ts +174 -0
- package/src/registry/operations/type-checking.ts +162 -0
- package/src/registry/operations/type-conversion.ts +404 -0
- package/src/registry/operations/type-operators.ts +308 -0
- package/src/registry/operations/utility.ts +644 -0
- package/src/registry/registry.ts +146 -0
- package/src/registry/types.ts +161 -0
- package/src/registry/utils/evaluation-helpers.ts +93 -0
- package/src/registry/utils/index.ts +3 -0
- package/src/registry/utils/type-system.ts +173 -0
- package/src/runtime/context.ts +158 -0
- package/src/runtime/debug-context.ts +135 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# with position tracking
|
|
2
|
+
|
|
3
|
+
- Total expressions tested: 1539
|
|
4
|
+
- Total iterations: 1,539,000
|
|
5
|
+
- Total time: 2.18s
|
|
6
|
+
- Time per expression: 0.0014ms
|
|
7
|
+
- Throughput: ~707,073 expressions per second
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# without position tracking
|
|
11
|
+
|
|
12
|
+
- Total expressions tested: 1539
|
|
13
|
+
- Total iterations: 1,539,000
|
|
14
|
+
- Total time: 1.96s
|
|
15
|
+
- Time per expression: 0.0013ms
|
|
16
|
+
- Throughput: ~783,321 expressions per second
|
|
17
|
+
|
|
18
|
+
Performance improvement:
|
|
19
|
+
- ~14.7% faster overall
|
|
20
|
+
- ~0.0002ms faster per expression
|
|
21
|
+
- ~103,102 more expressions per second
|
|
22
|
+
|
|
23
|
+
# without value building
|
|
24
|
+
|
|
25
|
+
- Total expressions: 1539
|
|
26
|
+
- Total iterations: 1539000
|
|
27
|
+
- Total time: 1.91s
|
|
28
|
+
- Time per expression: 0.0012ms
|
|
29
|
+
- Expressions per second: 807382
|
|
30
|
+
|
|
31
|
+
Before (without position tracking but with value strings):
|
|
32
|
+
|
|
33
|
+
- Time: ~1.94s
|
|
34
|
+
- Throughput: ~793,647 expressions/second
|
|
35
|
+
|
|
36
|
+
After (with position tracking, no value strings):
|
|
37
|
+
|
|
38
|
+
- Time: ~1.88s
|
|
39
|
+
- Throughput: ~817,240 expressions/second
|
|
40
|
+
|
|
41
|
+
Performance improvement: ~3% faster
|
|
42
|
+
|
|
43
|
+
The improvement is modest because:
|
|
44
|
+
1. We still need to traverse the input character by character for escape sequences
|
|
45
|
+
2. The main benefit is reduced memory allocation, not raw speed
|
|
46
|
+
3. Further optimizations (like character code comparisons instead of regex) would yield bigger gains
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# without regex
|
|
50
|
+
|
|
51
|
+
Total expressions: 1539
|
|
52
|
+
Total iterations: 1539000
|
|
53
|
+
Total time: 1.45s
|
|
54
|
+
Time per expression: 0.0009ms
|
|
55
|
+
Expressions per second: 1061465
|
|
56
|
+
|
|
57
|
+
1. Initial (with position tracking & value strings):
|
|
58
|
+
- ~705,096 expressions/sec
|
|
59
|
+
2. Without position tracking:
|
|
60
|
+
- ~793,647 expressions/sec (+12.6%)
|
|
61
|
+
3. With position ranges instead of value strings:
|
|
62
|
+
- ~817,240 expressions/sec (+15.9%)
|
|
63
|
+
4. With character code comparisons instead of regex:
|
|
64
|
+
- ~1,062,000 expressions/sec (+50.6%!)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
## Array optimization ( does not help )
|
|
68
|
+
The results show that:
|
|
69
|
+
1. String.charCodeAt() is the fastest - about 3% faster than charAt
|
|
70
|
+
2. Char arrays are actually slower - about 2.7% slower than string access
|
|
71
|
+
3. Uint16Array is also slower - about 2.4% slower
|
|
72
|
+
|
|
73
|
+
This is because:
|
|
74
|
+
- Modern JavaScript engines heavily optimize string operations
|
|
75
|
+
- Creating an array adds memory allocation overhead
|
|
76
|
+
- Array access isn't faster than optimized string access
|
|
77
|
+
- We lose the benefit of string interning and other V8 optimizations
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# First-character dispatch
|
|
81
|
+
|
|
82
|
+
Optimization Progression:
|
|
83
|
+
|
|
84
|
+
1. Initial (with position tracking & value strings):
|
|
85
|
+
- ~705,096 expressions/sec
|
|
86
|
+
2. Without position tracking:
|
|
87
|
+
- ~793,647 expressions/sec (+12.6%)
|
|
88
|
+
3. With position ranges instead of value strings:
|
|
89
|
+
- ~817,240 expressions/sec (+15.9%)
|
|
90
|
+
4. With character code comparisons:
|
|
91
|
+
- ~1,062,000 expressions/sec (+50.6%)
|
|
92
|
+
5. With switch-based token dispatch:
|
|
93
|
+
- ~1,363,000 expressions/sec (+93.4%!)
|
|
94
|
+
|
|
95
|
+
Latest Optimization Impact:
|
|
96
|
+
|
|
97
|
+
- Reduced time from ~1.45s to ~1.13s
|
|
98
|
+
- Increased throughput by ~300,000 expressions/second
|
|
99
|
+
- Time per expression dropped from 0.0009ms to 0.0007ms
|
|
100
|
+
|
|
101
|
+
Total Performance Improvement: ~93% faster than the original
|
|
102
|
+
|
|
103
|
+
The switch-based dispatch provided another significant performance boost (~28% over the previous version) because:
|
|
104
|
+
1. Direct jumps to the right token handler based on first character
|
|
105
|
+
2. No sequential checking of multiple token types
|
|
106
|
+
3. Better CPU branch prediction with switch statements
|
|
107
|
+
4. Eliminated unnecessary function calls for tokens that wouldn't match
|
|
108
|
+
|
|
109
|
+
## switch
|
|
110
|
+
|
|
111
|
+
Total expressions: 1539
|
|
112
|
+
Total iterations: 1539000
|
|
113
|
+
Total time: 1.12s
|
|
114
|
+
Time per expression: 0.0007ms
|
|
115
|
+
Expressions per second: 1375165
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Inline-hot functions
|
|
119
|
+
|
|
120
|
+
Optimization Progression:
|
|
121
|
+
|
|
122
|
+
1. Initial: ~705,096 expressions/sec
|
|
123
|
+
2. Without position tracking: ~793,647 expressions/sec (+12.6%)
|
|
124
|
+
3. Position ranges instead of values: ~817,240 expressions/sec (+15.9%)
|
|
125
|
+
4. Character code comparisons: ~1,062,000 expressions/sec (+50.6%)
|
|
126
|
+
5. Switch-based dispatch: ~1,363,000 expressions/sec (+93.4%)
|
|
127
|
+
6. Inlined hot functions: ~1,477,000 expressions/sec (+109.5%!)
|
|
128
|
+
|
|
129
|
+
Latest Optimization Impact:
|
|
130
|
+
|
|
131
|
+
- Reduced time from ~1.13s to ~1.04s
|
|
132
|
+
- Increased throughput by 114,000 expressions/second (8.4% improvement)
|
|
133
|
+
- Time per expression remains at 0.0007ms
|
|
134
|
+
|
|
135
|
+
Total Performance Improvement: ~109% faster (more than 2x the original speed!)
|
|
136
|
+
|
|
137
|
+
The function inlining provided a solid ~8% performance boost by:
|
|
138
|
+
1. Eliminating function call overhead in tight loops
|
|
139
|
+
2. Better CPU pipeline efficiency with fewer jumps
|
|
140
|
+
3. Reduced stack operations
|
|
141
|
+
4. Improved locality of reference
|
|
142
|
+
|
|
143
|
+
The lexer is now processing nearly 1.5 million FHIRPath expressions per second!
|
|
144
|
+
|
|
145
|
+
Remaining High-Impact Optimizations:
|
|
146
|
+
|
|
147
|
+
1. Lookup tables for character classification (could add 5-10%)
|
|
148
|
+
2. Optimize readSpecialIdentifier substring (could add 2-3%)
|
|
149
|
+
3. Perfect hash for keywords (could add 3-5%)
|
|
150
|
+
4. Switch on character codes instead of chars (could add 2-3%)
|
|
151
|
+
|
|
152
|
+
We've achieved excellent performance with clean, maintainable code!
|
|
153
|
+
|
|
154
|
+
## Lookup table optimization
|
|
155
|
+
|
|
156
|
+
The lookup tables optimization has been successfully implemented, improving performance by ~4.7% to reach ~1,546K expressions per second. All tests pass and the lexer maintains full compatibility.
|
|
157
|
+
|
|
158
|
+
Total expressions: 1539
|
|
159
|
+
Total iterations: 1539000
|
|
160
|
+
Total time: 0.98s
|
|
161
|
+
Time per expression: 0.0006ms
|
|
162
|
+
Expressions per second: 1569801
|
|
163
|
+
|
|
164
|
+
## Switch based keyword lookup
|
|
165
|
+
|
|
166
|
+
The switch-based keyword lookup was incredibly effective! We've achieved a 42% performance improvement with this optimization alone.
|
|
167
|
+
The total improvement from all optimizations is now from ~1,477K to ~2,192K expressions per second - a 48% overall improvement.
|
|
168
|
+
|
|
169
|
+
Total expressions: 1539
|
|
170
|
+
Total iterations: 1539000
|
|
171
|
+
Total time: 0.71s
|
|
172
|
+
Time per expression: 0.0005ms
|
|
173
|
+
Expressions per second: 2160611
|