@sun-asterisk/sunlint 1.3.2 → 1.3.3
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/CHANGELOG.md +38 -0
- package/README.md +5 -3
- package/config/rules/enhanced-rules-registry.json +144 -33
- package/core/analysis-orchestrator.js +167 -42
- package/core/auto-performance-manager.js +243 -0
- package/core/cli-action-handler.js +9 -1
- package/core/cli-program.js +19 -5
- package/core/constants/defaults.js +56 -0
- package/core/performance-optimizer.js +271 -0
- package/docs/FILE_LIMITS_COMPLETION_REPORT.md +151 -0
- package/docs/FILE_LIMITS_EXPLANATION.md +190 -0
- package/docs/PERFORMANCE.md +311 -0
- package/docs/PERFORMANCE_MIGRATION_GUIDE.md +368 -0
- package/docs/PERFORMANCE_OPTIMIZATION_PLAN.md +255 -0
- package/docs/QUICK_FILE_LIMITS.md +64 -0
- package/docs/SIMPLIFIED_USAGE_GUIDE.md +208 -0
- package/engines/heuristic-engine.js +182 -5
- package/package.json +2 -1
- package/rules/common/C048_no_bypass_architectural_layers/analyzer.js +180 -0
- package/rules/common/C048_no_bypass_architectural_layers/config.json +50 -0
- package/rules/common/C048_no_bypass_architectural_layers/symbol-based-analyzer.js +235 -0
- package/rules/common/C052_parsing_or_data_transformation/analyzer.js +180 -0
- package/rules/common/C052_parsing_or_data_transformation/config.json +50 -0
- package/rules/common/C052_parsing_or_data_transformation/symbol-based-analyzer.js +132 -0
- package/rules/index.js +2 -0
- package/rules/security/S017_use_parameterized_queries/README.md +128 -0
- package/rules/security/S017_use_parameterized_queries/analyzer.js +286 -0
- package/rules/security/S017_use_parameterized_queries/config.json +109 -0
- package/rules/security/S017_use_parameterized_queries/regex-based-analyzer.js +541 -0
- package/rules/security/S017_use_parameterized_queries/symbol-based-analyzer.js +777 -0
- package/rules/security/S031_secure_session_cookies/README.md +127 -0
- package/rules/security/S031_secure_session_cookies/analyzer.js +245 -0
- package/rules/security/S031_secure_session_cookies/config.json +86 -0
- package/rules/security/S031_secure_session_cookies/regex-based-analyzer.js +196 -0
- package/rules/security/S031_secure_session_cookies/symbol-based-analyzer.js +1084 -0
- package/rules/security/S032_httponly_session_cookies/FRAMEWORK_SUPPORT.md +209 -0
- package/rules/security/S032_httponly_session_cookies/README.md +184 -0
- package/rules/security/S032_httponly_session_cookies/analyzer.js +282 -0
- package/rules/security/S032_httponly_session_cookies/config.json +96 -0
- package/rules/security/S032_httponly_session_cookies/regex-based-analyzer.js +715 -0
- package/rules/security/S032_httponly_session_cookies/symbol-based-analyzer.js +1348 -0
- package/rules/security/S033_samesite_session_cookies/README.md +227 -0
- package/rules/security/S033_samesite_session_cookies/analyzer.js +242 -0
- package/rules/security/S033_samesite_session_cookies/config.json +87 -0
- package/rules/security/S033_samesite_session_cookies/regex-based-analyzer.js +703 -0
- package/rules/security/S033_samesite_session_cookies/symbol-based-analyzer.js +732 -0
- package/rules/security/S034_host_prefix_session_cookies/README.md +204 -0
- package/rules/security/S034_host_prefix_session_cookies/analyzer.js +290 -0
- package/rules/security/S034_host_prefix_session_cookies/config.json +62 -0
- package/rules/security/S034_host_prefix_session_cookies/regex-based-analyzer.js +478 -0
- package/rules/security/S034_host_prefix_session_cookies/symbol-based-analyzer.js +277 -0
- package/rules/security/S035_path_session_cookies/README.md +257 -0
- package/rules/security/S035_path_session_cookies/analyzer.js +316 -0
- package/rules/security/S035_path_session_cookies/config.json +99 -0
- package/rules/security/S035_path_session_cookies/regex-based-analyzer.js +724 -0
- package/rules/security/S035_path_session_cookies/symbol-based-analyzer.js +373 -0
- package/scripts/batch-processing-demo.js +334 -0
- package/scripts/performance-test.js +541 -0
- package/scripts/quick-performance-test.js +108 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# 🚀 SunLint Performance Migration Guide
|
|
2
|
+
|
|
3
|
+
## 🎯 Overview
|
|
4
|
+
|
|
5
|
+
With **73 heuristic rules** and growing, SunLint needs performance optimizations to handle enterprise-scale projects without timeouts or memory crashes. This guide helps you migrate to the optimized performance features in **SunLint v4.0**.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ⚠️ Current Performance Issues
|
|
10
|
+
|
|
11
|
+
### **Before Optimization**
|
|
12
|
+
```bash
|
|
13
|
+
# ❌ This will likely timeout on large projects
|
|
14
|
+
sunlint --all --input=src
|
|
15
|
+
|
|
16
|
+
# ❌ Memory exhaustion with 1000+ files
|
|
17
|
+
sunlint --rules=C019,C033,C047,C076 --input=large-project
|
|
18
|
+
|
|
19
|
+
# ❌ Stack overflow with complex projects
|
|
20
|
+
sunlint --all --input=enterprise-codebase
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### **Common Error Messages**
|
|
24
|
+
- `Engine heuristic failed: Engine undefined timed out after 30000ms`
|
|
25
|
+
- `Maximum call stack size exceeded`
|
|
26
|
+
- `JavaScript heap out of memory`
|
|
27
|
+
- `FATAL ERROR: Ineffective mark-compacts near heap limit`
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 🚀 Migration Steps
|
|
32
|
+
|
|
33
|
+
### **Step 1: Enable Performance Optimizations**
|
|
34
|
+
|
|
35
|
+
#### **Quick Fix: Use Performance Profile**
|
|
36
|
+
```bash
|
|
37
|
+
# ✅ BEFORE: Basic command (may timeout)
|
|
38
|
+
sunlint --all --input=src
|
|
39
|
+
|
|
40
|
+
# ✅ AFTER: With performance profile
|
|
41
|
+
sunlint --all --input=src --performance-profile=balanced
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### **Available Profiles**
|
|
45
|
+
| Profile | Best For | Timeout | Batch Size | Max Files |
|
|
46
|
+
|---------|----------|---------|------------|-----------|
|
|
47
|
+
| `fast` | < 100 files | 30s | 20 rules | 200 files |
|
|
48
|
+
| `balanced` | 100-500 files | 60s | 15 rules | 500 files |
|
|
49
|
+
| `careful` | 500-1000 files | 120s | 10 rules | 1000 files |
|
|
50
|
+
| `conservative` | 1000+ files | 300s | 5 rules | 1500 files |
|
|
51
|
+
|
|
52
|
+
### **Step 2: Configure Timeouts**
|
|
53
|
+
|
|
54
|
+
#### **Static Timeout**
|
|
55
|
+
```bash
|
|
56
|
+
# ✅ Set longer timeout for large projects
|
|
57
|
+
sunlint --all --input=src --timeout=120000 # 2 minutes
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### **Adaptive Timeout (Recommended)**
|
|
61
|
+
```bash
|
|
62
|
+
# ✅ Auto-scale timeout based on project size
|
|
63
|
+
sunlint --all --input=src --adaptive-timeout
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### **No Timeout (Use with Caution)**
|
|
67
|
+
```bash
|
|
68
|
+
# ⚠️ Disable timeout completely (for CI/CD environments)
|
|
69
|
+
sunlint --all --input=src --no-timeout
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### **Step 3: Memory Management**
|
|
73
|
+
|
|
74
|
+
#### **Set Memory Limits**
|
|
75
|
+
```bash
|
|
76
|
+
# ✅ Limit memory usage
|
|
77
|
+
sunlint --all --input=src --max-memory=2GB
|
|
78
|
+
|
|
79
|
+
# ✅ For containers with limited memory
|
|
80
|
+
sunlint --all --input=src --max-memory=1GB --streaming-analysis
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### **File Limits**
|
|
84
|
+
```bash
|
|
85
|
+
# ✅ Limit files to prevent memory explosion
|
|
86
|
+
sunlint --all --input=src --max-files=1000
|
|
87
|
+
|
|
88
|
+
# ✅ Smart sampling for huge projects
|
|
89
|
+
sunlint --all --input=src --smart-sampling --max-files=500
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### **Step 4: Batch Processing**
|
|
93
|
+
|
|
94
|
+
#### **Rule Batching**
|
|
95
|
+
```bash
|
|
96
|
+
# ✅ Process rules in smaller batches
|
|
97
|
+
sunlint --all --input=src --batch-size=10
|
|
98
|
+
|
|
99
|
+
# ✅ Parallel batch processing
|
|
100
|
+
sunlint --all --input=src --batch-size=10 --parallel-batches=2
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### **File Batching**
|
|
104
|
+
```bash
|
|
105
|
+
# ✅ Process files in batches for memory management
|
|
106
|
+
sunlint --all --input=src --file-batch-size=50
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### **Step 5: Progressive Results**
|
|
110
|
+
|
|
111
|
+
#### **Show Results as Found**
|
|
112
|
+
```bash
|
|
113
|
+
# ✅ See violations as they're discovered
|
|
114
|
+
sunlint --all --input=src --progressive-results
|
|
115
|
+
|
|
116
|
+
# ✅ For CI/CD: See progress without waiting
|
|
117
|
+
sunlint --all --input=src --progressive-results --verbose
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 🎛️ Complete Migration Examples
|
|
123
|
+
|
|
124
|
+
### **Small to Medium Projects (< 500 files)**
|
|
125
|
+
```bash
|
|
126
|
+
# BEFORE (v3.x)
|
|
127
|
+
sunlint --all --input=src --verbose
|
|
128
|
+
|
|
129
|
+
# AFTER (v4.x - Optimized)
|
|
130
|
+
sunlint --all --input=src \
|
|
131
|
+
--performance-profile=balanced \
|
|
132
|
+
--progressive-results \
|
|
133
|
+
--verbose
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### **Large Projects (500-1000 files)**
|
|
137
|
+
```bash
|
|
138
|
+
# BEFORE (v3.x) - Would likely timeout
|
|
139
|
+
sunlint --all --input=src --timeout=60000
|
|
140
|
+
|
|
141
|
+
# AFTER (v4.x - Optimized)
|
|
142
|
+
sunlint --all --input=src \
|
|
143
|
+
--performance-profile=careful \
|
|
144
|
+
--adaptive-timeout \
|
|
145
|
+
--max-files=1000 \
|
|
146
|
+
--batch-size=10 \
|
|
147
|
+
--progressive-results \
|
|
148
|
+
--verbose
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### **Enterprise Projects (1000+ files)**
|
|
152
|
+
```bash
|
|
153
|
+
# BEFORE (v3.x) - Would crash
|
|
154
|
+
sunlint --all --input=src
|
|
155
|
+
|
|
156
|
+
# AFTER (v4.x - Optimized)
|
|
157
|
+
sunlint --all --input=src \
|
|
158
|
+
--performance-profile=conservative \
|
|
159
|
+
--max-memory=2GB \
|
|
160
|
+
--max-files=1500 \
|
|
161
|
+
--streaming-analysis \
|
|
162
|
+
--smart-sampling \
|
|
163
|
+
--batch-size=5 \
|
|
164
|
+
--progressive-results \
|
|
165
|
+
--verbose
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### **CI/CD Pipeline Optimization**
|
|
169
|
+
```bash
|
|
170
|
+
# BEFORE (v3.x)
|
|
171
|
+
sunlint --all --input=src --format=json
|
|
172
|
+
|
|
173
|
+
# AFTER (v4.x - CI-Optimized)
|
|
174
|
+
sunlint --all --input=src \
|
|
175
|
+
--performance-profile=balanced \
|
|
176
|
+
--adaptive-timeout \
|
|
177
|
+
--progressive-results \
|
|
178
|
+
--format=json \
|
|
179
|
+
--quiet # Suppress progress for cleaner CI logs
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 🔧 Engine Selection
|
|
185
|
+
|
|
186
|
+
### **Use Optimized Engine**
|
|
187
|
+
```bash
|
|
188
|
+
# ✅ Use the new optimized engine
|
|
189
|
+
sunlint --all --input=src --engine=optimized
|
|
190
|
+
|
|
191
|
+
# ✅ Or force with performance profile
|
|
192
|
+
sunlint --all --input=src --performance-profile=balanced
|
|
193
|
+
# (automatically uses optimized engine)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### **Fallback to Legacy Engine**
|
|
197
|
+
```bash
|
|
198
|
+
# ⚠️ Only if optimized engine has issues
|
|
199
|
+
sunlint --all --input=src --legacy
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 📊 Performance Monitoring
|
|
205
|
+
|
|
206
|
+
### **Verbose Output for Performance Insights**
|
|
207
|
+
```bash
|
|
208
|
+
# ✅ See detailed performance metrics
|
|
209
|
+
sunlint --all --input=src \
|
|
210
|
+
--performance-profile=balanced \
|
|
211
|
+
--verbose
|
|
212
|
+
|
|
213
|
+
# Output example:
|
|
214
|
+
# 🚀 Analysis started with performance profile: Balanced
|
|
215
|
+
# ⚡ Processing batch 1/5 (15 rules)...
|
|
216
|
+
# 📊 Analyzed 245/1000 files (24.5%)
|
|
217
|
+
# 🎯 Found 23 violations so far...
|
|
218
|
+
# ✅ Analysis completed in 45.2s:
|
|
219
|
+
# 📁 Files: 1000
|
|
220
|
+
# 📋 Rules: 73
|
|
221
|
+
# 🎯 Violations: 156
|
|
222
|
+
# 💾 Peak Memory: 1.2GB
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### **Performance Testing**
|
|
226
|
+
```bash
|
|
227
|
+
# ✅ Test performance with your project
|
|
228
|
+
node scripts/performance-test.js
|
|
229
|
+
|
|
230
|
+
# ✅ Demo batch processing
|
|
231
|
+
node scripts/batch-processing-demo.js
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## 🚨 Troubleshooting
|
|
237
|
+
|
|
238
|
+
### **Still Getting Timeouts?**
|
|
239
|
+
|
|
240
|
+
1. **Increase timeout**:
|
|
241
|
+
```bash
|
|
242
|
+
sunlint --all --input=src --timeout=300000 # 5 minutes
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
2. **Reduce scope**:
|
|
246
|
+
```bash
|
|
247
|
+
sunlint --all --input=src --max-files=500
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
3. **Use smaller batches**:
|
|
251
|
+
```bash
|
|
252
|
+
sunlint --all --input=src --batch-size=5
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
4. **Enable streaming**:
|
|
256
|
+
```bash
|
|
257
|
+
sunlint --all --input=src --streaming-analysis
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### **Memory Issues?**
|
|
261
|
+
|
|
262
|
+
1. **Set memory limit**:
|
|
263
|
+
```bash
|
|
264
|
+
sunlint --all --input=src --max-memory=1GB
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
2. **Reduce file batch size**:
|
|
268
|
+
```bash
|
|
269
|
+
sunlint --all --input=src --file-batch-size=25
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
3. **Use smart sampling**:
|
|
273
|
+
```bash
|
|
274
|
+
sunlint --all --input=src --smart-sampling --max-files=300
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### **Poor Performance?**
|
|
278
|
+
|
|
279
|
+
1. **Use fast profile for testing**:
|
|
280
|
+
```bash
|
|
281
|
+
sunlint --rules=C002,C003,C006 --input=src --performance-profile=fast
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
2. **Check file exclusions**:
|
|
285
|
+
```bash
|
|
286
|
+
sunlint --all --input=src --exclude="node_modules/**,dist/**,build/**"
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
3. **Limit semantic analysis**:
|
|
290
|
+
```bash
|
|
291
|
+
sunlint --all --input=src --max-semantic-files=200
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## 📈 Performance Benchmarks
|
|
297
|
+
|
|
298
|
+
### **Target Performance** (v4.x Optimized)
|
|
299
|
+
|
|
300
|
+
| Project Size | Files | Rules | Expected Time | Memory Usage |
|
|
301
|
+
|--------------|-------|-------|---------------|--------------|
|
|
302
|
+
| **Small** | 50 | 20 | ~10s | 500MB |
|
|
303
|
+
| **Medium** | 200 | 35 | ~30s | 1GB |
|
|
304
|
+
| **Large** | 500 | 50 | ~60s | 1.5GB |
|
|
305
|
+
| **Enterprise** | 1000+ | 73 | ~120s | 2GB |
|
|
306
|
+
|
|
307
|
+
### **Performance Improvements**
|
|
308
|
+
|
|
309
|
+
| Scenario | v3.x (Before) | v4.x (After) | Improvement |
|
|
310
|
+
|----------|---------------|--------------|-------------|
|
|
311
|
+
| **Medium Project** | Timeout (30s) | 45s | **Functional** |
|
|
312
|
+
| **Large Project** | Memory crash | 90s | **3x faster** |
|
|
313
|
+
| **Enterprise** | Impossible | 180s | **Breakthrough** |
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## 🏁 Quick Start Checklist
|
|
318
|
+
|
|
319
|
+
- [ ] **Update to SunLint v4.x** with performance optimizations
|
|
320
|
+
- [ ] **Choose performance profile** based on your project size
|
|
321
|
+
- [ ] **Enable adaptive timeout** for automatic scaling
|
|
322
|
+
- [ ] **Set memory limits** appropriate for your environment
|
|
323
|
+
- [ ] **Use progressive results** for better user experience
|
|
324
|
+
- [ ] **Test with your actual codebase** to validate performance
|
|
325
|
+
- [ ] **Monitor memory usage** and adjust limits as needed
|
|
326
|
+
- [ ] **Consider smart sampling** for extremely large projects
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 🎯 Best Practices
|
|
331
|
+
|
|
332
|
+
### **Development**
|
|
333
|
+
```bash
|
|
334
|
+
# Fast feedback during development
|
|
335
|
+
sunlint --rules=C002,C019,S027 --input=src --performance-profile=fast
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### **Pre-commit**
|
|
339
|
+
```bash
|
|
340
|
+
# Quick check on changed files
|
|
341
|
+
sunlint --all --changed-files --performance-profile=fast
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### **CI/CD**
|
|
345
|
+
```bash
|
|
346
|
+
# Comprehensive analysis with performance safety
|
|
347
|
+
sunlint --all --input=src \
|
|
348
|
+
--performance-profile=balanced \
|
|
349
|
+
--adaptive-timeout \
|
|
350
|
+
--format=json \
|
|
351
|
+
--output=sunlint-results.json
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### **Weekly Code Quality Review**
|
|
355
|
+
```bash
|
|
356
|
+
# Full analysis with detailed reporting
|
|
357
|
+
sunlint --all --input=src \
|
|
358
|
+
--performance-profile=careful \
|
|
359
|
+
--progressive-results \
|
|
360
|
+
--format=table \
|
|
361
|
+
--verbose
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
**Performance optimization is critical for SunLint adoption at enterprise scale. These optimizations ensure that SunLint remains fast and reliable as your codebase grows.**
|
|
367
|
+
|
|
368
|
+
*🚀 Scale with Confidence • ⚡ Optimized Performance • 🎯 Enterprise Ready*
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# 🚀 SunLint Performance Optimization Plan
|
|
2
|
+
|
|
3
|
+
## 📊 Current Performance Challenges
|
|
4
|
+
|
|
5
|
+
### **Critical Issues Identified**
|
|
6
|
+
1. **Timeout Issues**: `Engine heuristic failed: Engine undefined timed out after 30000ms`
|
|
7
|
+
2. **Memory Exhaustion**: `Maximum call stack size exceeded` with large projects
|
|
8
|
+
3. **Symbol Table Bottleneck**: Loading 73 rules × large file count = performance disaster
|
|
9
|
+
4. **Batch Processing Gap**: No intelligent rule batching for large projects
|
|
10
|
+
|
|
11
|
+
### **Performance Metrics (Current)**
|
|
12
|
+
- **Total Rules**: 100 (Common: 34, Security: 49, Others: 17)
|
|
13
|
+
- **SunLint Rules**: 73 rules with analyzers (3x growth from ~22)
|
|
14
|
+
- **AST-Powered**: 65+ rules requiring semantic analysis
|
|
15
|
+
- **Memory Impact**: Symbol table × file count × rule count = O(n³) complexity
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🎯 Optimization Strategy
|
|
20
|
+
|
|
21
|
+
### **Phase 1: Immediate Performance Fixes**
|
|
22
|
+
|
|
23
|
+
#### **1.1 Timeout Management**
|
|
24
|
+
```bash
|
|
25
|
+
# Current: Fixed 30s timeout
|
|
26
|
+
# Solution: Dynamic timeout based on project size
|
|
27
|
+
--timeout=60000 # 60s for large projects
|
|
28
|
+
--timeout=120000 # 120s for enterprise projects
|
|
29
|
+
--adaptive-timeout # Auto-scale based on file count
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### **1.2 File Filtering Enhancement**
|
|
33
|
+
```bash
|
|
34
|
+
# Current: Basic exclude patterns
|
|
35
|
+
# Solution: Smart exclusion patterns
|
|
36
|
+
--exclude-patterns="node_modules/**,.next/**,dist/**,build/**"
|
|
37
|
+
--max-files=1000 # Hard limit for safety
|
|
38
|
+
--smart-sampling # Intelligent file sampling for large projects
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### **1.3 Rule Batching**
|
|
42
|
+
```bash
|
|
43
|
+
# Current: All rules processed together
|
|
44
|
+
# Solution: Intelligent rule batching
|
|
45
|
+
--batch-size=10 # Process 10 rules at a time
|
|
46
|
+
--priority-rules=C019,S027,C041 # High-priority rules first
|
|
47
|
+
--parallel-batches=2 # Parallel batch processing
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### **Phase 2: Memory Optimization**
|
|
51
|
+
|
|
52
|
+
#### **2.1 Symbol Table Streaming**
|
|
53
|
+
```javascript
|
|
54
|
+
// Current: Load all files into memory
|
|
55
|
+
const symbolTable = await loadAllFiles(); // ❌ Memory explosion
|
|
56
|
+
|
|
57
|
+
// Solution: Streaming symbol table
|
|
58
|
+
const symbolTable = new StreamingSymbolTable({
|
|
59
|
+
maxMemoryFiles: 100, // Keep max 100 files in memory
|
|
60
|
+
swapToTemp: true, // Swap to temp files when needed
|
|
61
|
+
lazyLoading: true // Load files on-demand
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### **2.2 Rule-Specific Analysis**
|
|
66
|
+
```javascript
|
|
67
|
+
// Current: All rules analyze all files
|
|
68
|
+
rules.forEach(rule => files.forEach(file => rule.analyze(file))); // ❌ O(n²)
|
|
69
|
+
|
|
70
|
+
// Solution: Smart rule targeting
|
|
71
|
+
const fileToRulesMap = buildFileRuleMapping(files, rules);
|
|
72
|
+
fileToRulesMap.forEach((rules, file) => {
|
|
73
|
+
rules.forEach(rule => rule.analyze(file)); // ✅ Optimized
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### **Phase 3: Architecture Optimization**
|
|
78
|
+
|
|
79
|
+
#### **3.1 Worker Process Architecture**
|
|
80
|
+
```javascript
|
|
81
|
+
// Solution: Multi-process rule execution
|
|
82
|
+
const workers = {
|
|
83
|
+
syntaxRules: createWorker('./workers/syntax-rules.js'),
|
|
84
|
+
securityRules: createWorker('./workers/security-rules.js'),
|
|
85
|
+
semanticRules: createWorker('./workers/semantic-rules.js')
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Distribute rules across workers
|
|
89
|
+
const results = await Promise.all([
|
|
90
|
+
workers.syntaxRules.analyze(files, syntaxRules),
|
|
91
|
+
workers.securityRules.analyze(files, securityRules),
|
|
92
|
+
workers.semanticRules.analyze(files, semanticRules)
|
|
93
|
+
]);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### **3.2 Progressive Analysis**
|
|
97
|
+
```javascript
|
|
98
|
+
// Solution: Progressive disclosure of violations
|
|
99
|
+
const analyzer = new ProgressiveAnalyzer({
|
|
100
|
+
fastRules: ['C002', 'C003', 'C006'], // Quick regex rules first
|
|
101
|
+
mediumRules: ['C019', 'C041', 'S027'], // Moderate AST rules
|
|
102
|
+
slowRules: ['C033', 'C047', 'C076'] // Heavy semantic rules last
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Show results progressively
|
|
106
|
+
analyzer.on('fastComplete', (violations) => {
|
|
107
|
+
console.log(`Quick scan: ${violations.length} issues found`);
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 🛠️ Implementation Roadmap
|
|
114
|
+
|
|
115
|
+
### **Week 1: Critical Fixes**
|
|
116
|
+
- [ ] **Dynamic timeout configuration**
|
|
117
|
+
- [ ] **Enhanced file exclusion patterns**
|
|
118
|
+
- [ ] **Memory limit safeguards**
|
|
119
|
+
- [ ] **Rule batching implementation**
|
|
120
|
+
|
|
121
|
+
### **Week 2: Memory Optimization**
|
|
122
|
+
- [ ] **Streaming symbol table**
|
|
123
|
+
- [ ] **File-to-rule mapping optimization**
|
|
124
|
+
- [ ] **Lazy loading for AST analysis**
|
|
125
|
+
- [ ] **Memory monitoring & alerts**
|
|
126
|
+
|
|
127
|
+
### **Week 3: Architecture Enhancement**
|
|
128
|
+
- [ ] **Worker process architecture**
|
|
129
|
+
- [ ] **Progressive analysis pipeline**
|
|
130
|
+
- [ ] **Parallel rule execution**
|
|
131
|
+
- [ ] **Result caching system**
|
|
132
|
+
|
|
133
|
+
### **Week 4: Testing & Validation**
|
|
134
|
+
- [ ] **Performance benchmarking**
|
|
135
|
+
- [ ] **Large project testing**
|
|
136
|
+
- [ ] **Memory leak detection**
|
|
137
|
+
- [ ] **Timeout scenario testing**
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 📈 Expected Performance Improvements
|
|
142
|
+
|
|
143
|
+
### **Target Metrics**
|
|
144
|
+
| **Scenario** | **Current** | **Target** | **Improvement** |
|
|
145
|
+
|--------------|-------------|------------|-----------------|
|
|
146
|
+
| **Small Project** (< 100 files) | 30s | 10s | **3x faster** |
|
|
147
|
+
| **Medium Project** (100-500 files) | Timeout | 45s | **Functional** |
|
|
148
|
+
| **Large Project** (500+ files) | Memory crash | 120s | **Functional** |
|
|
149
|
+
| **Enterprise Project** (1000+ files) | Impossible | 300s | **Breakthrough** |
|
|
150
|
+
|
|
151
|
+
### **Memory Usage**
|
|
152
|
+
| **Project Size** | **Current** | **Target** | **Reduction** |
|
|
153
|
+
|------------------|-------------|------------|---------------|
|
|
154
|
+
| **100 files** | 2GB | 500MB | **75% reduction** |
|
|
155
|
+
| **500 files** | Crash | 1.5GB | **Functional** |
|
|
156
|
+
| **1000+ files** | Crash | 3GB | **Controlled** |
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🚦 Performance Monitoring
|
|
161
|
+
|
|
162
|
+
### **Key Performance Indicators (KPIs)**
|
|
163
|
+
```javascript
|
|
164
|
+
const performanceMetrics = {
|
|
165
|
+
// Analysis Speed
|
|
166
|
+
rulesPerSecond: target >= 5,
|
|
167
|
+
filesPerSecond: target >= 20,
|
|
168
|
+
violationsPerSecond: target >= 100,
|
|
169
|
+
|
|
170
|
+
// Memory Efficiency
|
|
171
|
+
memoryUsage: target <= '2GB',
|
|
172
|
+
memoryGrowthRate: target <= '10MB/min',
|
|
173
|
+
garbageCollectionFreq: target <= '5/min',
|
|
174
|
+
|
|
175
|
+
// Reliability
|
|
176
|
+
timeoutRate: target <= '1%',
|
|
177
|
+
crashRate: target <= '0.1%',
|
|
178
|
+
successRate: target >= '99%'
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### **Performance Alerts**
|
|
183
|
+
```bash
|
|
184
|
+
# Memory warnings
|
|
185
|
+
if (memoryUsage > 1.5GB) warn("High memory usage detected");
|
|
186
|
+
if (memoryUsage > 2.5GB) error("Memory limit approaching");
|
|
187
|
+
|
|
188
|
+
# Timeout warnings
|
|
189
|
+
if (analysisTime > 60s) warn("Analysis taking longer than expected");
|
|
190
|
+
if (analysisTime > 120s) error("Consider using --max-files or --batch-size");
|
|
191
|
+
|
|
192
|
+
# Progress indicators
|
|
193
|
+
echo "⚡ Processing batch 1/5 (20 rules)..."
|
|
194
|
+
echo "📊 Analyzed 245/1000 files (24.5%)"
|
|
195
|
+
echo "🎯 Found 23 violations so far..."
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 🔧 CLI Enhancement
|
|
201
|
+
|
|
202
|
+
### **New Performance Options**
|
|
203
|
+
```bash
|
|
204
|
+
# Timeout Management
|
|
205
|
+
sunlint --timeout=120000 # 2 minutes timeout
|
|
206
|
+
sunlint --adaptive-timeout # Auto-scale timeout
|
|
207
|
+
sunlint --no-timeout # Disable timeout (careful!)
|
|
208
|
+
|
|
209
|
+
# Memory Management
|
|
210
|
+
sunlint --max-memory=2GB # Memory limit
|
|
211
|
+
sunlint --max-files=1000 # File count limit
|
|
212
|
+
sunlint --streaming-analysis # Use streaming mode
|
|
213
|
+
|
|
214
|
+
# Batch Processing
|
|
215
|
+
sunlint --batch-size=10 # Rules per batch
|
|
216
|
+
sunlint --parallel-batches=2 # Parallel processing
|
|
217
|
+
sunlint --progressive-results # Show results as available
|
|
218
|
+
|
|
219
|
+
# Performance Profiles
|
|
220
|
+
sunlint --performance-profile=fast # Quick scan (30 rules)
|
|
221
|
+
sunlint --performance-profile=balanced # Standard scan (50 rules)
|
|
222
|
+
sunlint --performance-profile=comprehensive # Full scan (73 rules)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### **Smart Defaults Based on Project Size**
|
|
226
|
+
```javascript
|
|
227
|
+
const performanceProfiles = {
|
|
228
|
+
small: { files: '<100', timeout: 30000, batchSize: 20, rules: 'fast' },
|
|
229
|
+
medium: { files: '100-500', timeout: 60000, batchSize: 15, rules: 'balanced' },
|
|
230
|
+
large: { files: '500-1000', timeout: 120000, batchSize: 10, rules: 'essential' },
|
|
231
|
+
enterprise: { files: '>1000', timeout: 300000, batchSize: 5, rules: 'critical' }
|
|
232
|
+
};
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## 🏆 Success Criteria
|
|
238
|
+
|
|
239
|
+
### **Performance Goals**
|
|
240
|
+
- ✅ **Zero timeouts** on projects < 1000 files
|
|
241
|
+
- ✅ **Predictable memory usage** (linear growth, not exponential)
|
|
242
|
+
- ✅ **Progressive results** (show violations as they're found)
|
|
243
|
+
- ✅ **Graceful degradation** (intelligent fallbacks for large projects)
|
|
244
|
+
|
|
245
|
+
### **User Experience Goals**
|
|
246
|
+
- ✅ **Clear progress indicators** during long analyses
|
|
247
|
+
- ✅ **Meaningful performance warnings** before problems occur
|
|
248
|
+
- ✅ **Smart defaults** based on project size
|
|
249
|
+
- ✅ **Escape hatches** for power users (custom timeouts, batch sizes)
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
**Performance optimization is critical for SunLint adoption at scale. With 73 heuristic rules and growing, we must proactively address performance bottlenecks to maintain developer experience quality.**
|
|
254
|
+
|
|
255
|
+
*Engineering Excellence • Performance • Scalability*
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# 🎯 Quick Reference: File Limits
|
|
2
|
+
|
|
3
|
+
## **TL;DR: When to Use Each Option**
|
|
4
|
+
|
|
5
|
+
### **🤖 Most Users (90%)**
|
|
6
|
+
```bash
|
|
7
|
+
# ✅ Just use auto-detection - no manual limits needed
|
|
8
|
+
sunlint --all --input=src
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### **⚡ Performance Tuning (10%)**
|
|
12
|
+
```bash
|
|
13
|
+
# ✅ Both limits for different purposes
|
|
14
|
+
sunlint --all --input=src --max-files=1000 --max-semantic-files=300
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## **Quick Decision Matrix**
|
|
20
|
+
|
|
21
|
+
| **Situation** | **Use `--max-files`** | **Use `--max-semantic-files`** |
|
|
22
|
+
|---------------|----------------------|---------------------------------|
|
|
23
|
+
| 🐌 **Slow analysis** | ✅ YES - Limit total work | ❌ Not needed |
|
|
24
|
+
| 💾 **Memory issues** | ✅ YES - Reduce base memory | ✅ YES - Reduce symbol table |
|
|
25
|
+
| 🔍 **TypeScript heavy** | ❌ Not main issue | ✅ YES - Limit ts-morph memory |
|
|
26
|
+
| 🚀 **CI/CD timeout** | ✅ YES - Faster completion | ✅ YES - Less parsing |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## **📊 Memory Impact**
|
|
31
|
+
|
|
32
|
+
### **Analysis Files (`--max-files`)**
|
|
33
|
+
- **50MB** → 1000 files
|
|
34
|
+
- **100MB** → 2000 files
|
|
35
|
+
- **Impact**: Base memory + file reading
|
|
36
|
+
|
|
37
|
+
### **Symbol Table Files (`--max-semantic-files`)**
|
|
38
|
+
- **200MB** → 100 TypeScript files
|
|
39
|
+
- **1GB** → 500 TypeScript files
|
|
40
|
+
- **Impact**: AST parsing + type information
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## **🎛️ Common Patterns**
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 🏢 Enterprise (safe defaults)
|
|
48
|
+
--max-files=800 --max-semantic-files=200
|
|
49
|
+
|
|
50
|
+
# 🚀 CI/CD (fast & reliable)
|
|
51
|
+
--max-files=500 --max-semantic-files=100
|
|
52
|
+
|
|
53
|
+
# 🔍 TypeScript focus (more symbol table)
|
|
54
|
+
--max-files=600 --max-semantic-files=400
|
|
55
|
+
|
|
56
|
+
# 📦 JavaScript mainly (less symbol table)
|
|
57
|
+
--max-files=1500 --max-semantic-files=50
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
**💡 Key Insight: Symbol table limit should typically be smaller than analysis limit due to higher memory usage per file.**
|
|
63
|
+
|
|
64
|
+
*See [FILE_LIMITS_EXPLANATION.md](./FILE_LIMITS_EXPLANATION.md) for detailed explanation.*
|