Skip to content

JSL Performance Philosophy

The Spectrum of Optimization

JSL's postfix representation could be further optimized into raw primitives:

Current postfix:     [2, 3, "+", 4, "*"]
Could become:        [PUSH_INT, 2, PUSH_INT, 3, ADD, PUSH_INT, 4, MUL]
Or even:            [0x12, 0x02, 0x12, 0x03, 0x20, 0x12, 0x04, 0x21]

Why We Don't

We deliberately keep the postfix representation as JSON-compatible values rather than raw bytecode because:

1. Network Transparency

// This can be sent over HTTP, stored in databases, inspected by humans
[10, 20, "+", 100, 50, "-", "*"]

// This is opaque binary data
[0x0A, 0x14, 0x20, 0x64, 0x32, 0x22, 0x21]

2. Debugging & Introspection

Our postfix is self-documenting:

[2, 3, "+"]  # Obviously: 2 + 3
[0x02, 0x03, 0x20]  # What does this mean?

3. Universal Serialization

JSON works everywhere - browsers, databases, message queues, REST APIs. Binary formats require custom parsers and version management.

4. The Real Bottleneck

For 99% of distributed computing tasks, the bottleneck isn't instruction dispatch but: - Network latency (100,000x slower than CPU) - Database queries (10,000x slower) - Serialization/deserialization - Coordination overhead

5. Mobility Over Speed

JSL prioritizes computation mobility over raw performance:

# This is our superpower - pause here, resume there
state = {
    "stack": [30, 100],
    "code": [50, "-", "*"],
    "pc": 2
}
# Can be sent to any machine, stored, inspected, modified

When You Need Real Speed

If you need maximum performance:

  1. Wrong tool: JSL isn't for high-performance computing
  2. Use native code: C++, Rust, or assembly for hot paths
  3. JIT compilation: Compile hot JSL functions to native code
  4. Hybrid approach: JSL for coordination, native for computation
# JSL for orchestration
["parallel-map", 
  ["native-function", "fast_matrix_multiply"],
  large_dataset]

# Where fast_matrix_multiply is implemented in C++

The 80/20 Rule

80% of your code runs 20% of the time. JSL is perfect for that 80%: - Configuration - Orchestration
- Business logic - Data transformation - API endpoints

The other 20% that needs speed? Call out to native code.

Educational Value

Showing the progression of representations teaches important lessons:

Mathematical:    (λ (x) (× x x))
S-expression:    (lambda (x) (* x x))
JSON:           ["lambda", ["x"], ["*", "x", "x"]]
Postfix:        ["x", "x", "*", ("lambda", 1)]
Bytecode:       [LOAD_VAR, 0, LOAD_VAR, 0, MUL, MAKE_CLOSURE, 1]
Assembly:       mov eax, [ebp-4]; mov ebx, [ebp-4]; imul eax, ebx
Machine code:   8B 45 FC 8B 5D FC 0F AF C3

Each level trades human-readability for machine-efficiency. JSL stops at the postfix level because:

  1. It's still JSON - universally readable
  2. It's resumable - can pause/resume execution
  3. It's portable - works on any platform
  4. It's inspectable - can debug and understand
  5. It's fast enough - for distributed/networked computing

The JSL Philosophy

"Make it work, make it right, make it mobile. If you still need to make it fast, you're using the wrong tool."

JSL is about moving computation, not optimizing cycles. It's about expressing ideas clearly, not squeezing out nanoseconds. It's about universal computation, not platform-specific performance.

Conclusion

Could we compile JSL to raw bytecode? Yes. Should we? No.

The JSON-based postfix representation is the sweet spot: - Fast enough for real work - Clear enough for debugging - Portable enough for the network - Simple enough for implementation

If you need more speed than JSL provides, you don't need a faster JSL - you need a different language for that component. JSL's job is to coordinate, not to compete with C++.

Remember: Premature optimization is the root of all evil (Knuth), and in distributed systems, the network is the computer (Sun Microsystems). JSL embraces both principles.