Skip to content

Commit a9db01e

Browse files
fglockclaude
andcommitted
Update interpreter documentation with Phase 2 results
Updated documentation in dev/interpreter/ to reflect completion of array operator implementation and benchmark results: OPTIMIZATION_RESULTS.md: - Added Phase 2 array operator optimizations - Loop benchmark with 100M iterations - Compiler mode 78% faster than Perl 5 - Interpreter only 15% slower than Perl 5 - All 51 array.t tests passing STATUS.md: - Complete rewrite reflecting current state - Phase 2 completion status - Production readiness assessment - Benchmark results and analysis - Architecture highlights with short[] bytecode - Recent optimizations documented Key achievements: - Context propagation working - Register management handles 65K registers - Performance competitive with Perl 5 - All array operators functional Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 22799c6 commit a9db01e

File tree

2 files changed

+275
-120
lines changed

2 files changed

+275
-120
lines changed

dev/interpreter/OPTIMIZATION_RESULTS.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,96 @@ The interpreter is production-ready for:
222222
achieving native Perl performance where compilation overhead would dominate.
223223

224224
Next steps: Profile-guided optimization to identify highest-impact improvements for general code.
225+
226+
## Phase 2: Array Operator Optimizations (2026-02-13)
227+
228+
### Optimizations Implemented
229+
230+
#### 1. Context Propagation
231+
- **Problem**: Array operations returning size instead of array in LIST context
232+
- **Solution**: Implemented try-finally blocks for context restoration (matching codegen)
233+
- **Impact**: Fixed `\@array` creating reference to size instead of array
234+
- **Tests**: array.t tests 1-22 now pass
235+
236+
#### 2. Variable Scoping
237+
- **Problem**: Bare blocks not cleaning up lexical variables
238+
- **Solution**: Added enterScope()/exitScope() to For3Node bare block handling
239+
- **Impact**: Fixed variable shadowing bugs (`my $array` in inner block)
240+
- **Tests**: Proper cleanup after scope exit
241+
242+
#### 3. Register Allocation Fix (Critical)
243+
- **Problem**: Register wraparound at 256 causing silent aliasing bugs
244+
- Register indices stored as bytes (0-255)
245+
- After 255 allocations, wrapped to 0, overwriting lexical variables
246+
- Manifested as "RuntimeScalar instead of RuntimeArray" errors
247+
- **Solution**: Converted bytecode from `byte[]` to `short[]`
248+
- Registers now support 0-65,535 (16-bit unsigned)
249+
- Cleaner implementation (no bit-packing)
250+
- Integer constants stored as 2 shorts
251+
- **Impact**: Eliminated entire class of aliasing bugs
252+
- **Tests**: All 51 array.t tests now pass
253+
254+
#### 4. Performance Optimizations
255+
- **Removed 0xFFFF masks**: Unnecessary for most values, kept only in readInt()
256+
- **Polymorphic scalar()**: Replaced instanceof checks with polymorphic method call
257+
- **Benefits**:
258+
- Fewer instructions per operation
259+
- Better branch prediction
260+
- Simpler, more maintainable code
261+
262+
### Loop Increment Benchmark (100M iterations)
263+
264+
**Test Code:**
265+
```perl
266+
my $sum = 0;
267+
for (my $i = 0; $i < 100_000_000; $i++) {
268+
$sum += $i;
269+
}
270+
```
271+
272+
**Results:**
273+
274+
| Implementation | Time | Relative to Perl 5 | Throughput |
275+
|---------------------|--------|-------------------|-------------|
276+
| Perl 5 | 1.53s | 1.00x (baseline) | 65.4M ops/s |
277+
| PerlOnJava Compiler | 0.86s | **1.78x faster**| 116.3M ops/s |
278+
| PerlOnJava Interp | 1.80s | 0.85x (15% slower) | 55.6M ops/s |
279+
280+
**Analysis:**
281+
282+
**Compiler mode exceeds Perl 5 by 78%**
283+
- JVM JIT (C2 compiler) optimizes tight loops extremely well
284+
- Unboxed integer operations provide significant speedup
285+
- Production-ready for CPU-intensive workloads
286+
287+
**Interpreter competitive with Perl 5**
288+
- Only 15% slower despite being a pure interpreter
289+
- Switch-based dispatch with tableswitch working well
290+
- Excellent for development, debugging, and eval STRING use cases
291+
292+
**Key Achievements:**
293+
1. ✅ All 51 array.t tests pass with interpreter
294+
2. ✅ Context propagation working correctly
295+
3. ✅ Register management handles large subroutines (65K registers)
296+
4. ✅ Performance competitive with Perl 5 interpreter
297+
5. ✅ Compiler mode significantly faster than Perl 5
298+
299+
### Production Readiness
300+
301+
**Compiler Mode: ✅ Production Ready**
302+
- 78% faster than Perl 5 for numeric code
303+
- Mature, well-tested
304+
- Best for long-running applications
305+
306+
**Interpreter Mode: ✅ Ready for Specific Use Cases**
307+
- Primary: Dynamic eval STRING (46x faster than compilation)
308+
- Secondary: Development/debugging, one-off scripts
309+
- Array operators fully functional
310+
- 15% slower than Perl 5, but acceptable for its use cases
311+
312+
**Recommended Strategy:**
313+
- Use compiler by default for production
314+
- Use interpreter for:
315+
- eval STRING with dynamic/unique code
316+
- Development and testing (faster iteration)
317+
- Short-lived scripts where compilation overhead dominates

0 commit comments

Comments
 (0)