RFC: Optimizing Player-UI DSL Compilation Performance #617
rafbcampos
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
RFC: Optimizing Player-UI DSL Compilation Performance
1. Summary
This RFC proposes targeted solutions to improve Player-UI DSL compilation performance.
Our benchmarking and analysis reveal significant performance opportunities through two distinct approaches:
These recommendations address critical performance bottlenecks while balancing developer experience and implementation feasibility.
2. Current Challenges
2.1 Content Authoring Approaches
Player-UI currently supports two methods for content authoring:
JSON
React DSL
The React approach relies on react-json-reconciler, which waits for all
useEffect
andsetState
updates to settle before returning results, constrained by both React APIs and JS runtime limitations.2.2 Performance Limitations
Recent requirements to perform DSL compilation at runtime have exposed significant performance issues:
2.3 Root Cause Analysis
Our performance profiling identified these key bottlenecks:
React Reconciliation Overhead
Implementation Inefficiencies
3. Proposed Solutions
3.1 Function Composition Approach
Benefits
Drawbacks
Performance Metrics (Average Execution Time in ms)
3.2 SolidJS Migration
Benefits
Drawbacks
Migration Strategy: Partially automated using code mods for API conversion.
Performance Metrics (Average Execution Time in ms)
3.3 Custom JSX runtime (React-like API)
Benefits
Drawbacks
Migration Strategy: Drop-in replacement.
Performance Metrics (Average Execution Time in ms)
4. The Case for a Functional DSL Approach
While the argument that DSL should prioritize user-friendliness over performance has merit, it creates a false dichotomy that doesn't reflect our actual options. The functional approach provides both superior performance and a clear, purpose-driven developer experience that better aligns with our DSL's fundamental purpose.
We introduced React as our DSL solution when direct JSON authoring proved cumbersome, but this was a compromise born of expedience rather than optimal design. JSON was difficult to author directly, so we leveraged a familiar tool (React) as a stopgap. However, we shouldn't confuse familiarity with superiority. The React approach introduced significant overhead and dependencies, effectively asking a UI rendering library to perform a task it wasn't designed for – generating structured data.
The functional approach delivers all the benefits that initially drove us to React – strong typing, IDE auto-completion, composition patterns, and quality-of-life features like ID generation – while eliminating the unnecessary overhead of Virtual DOM reconciliation, component lifecycle management, and state handling systems that contribute nothing to our actual goal of generating Player-UI content.
The mental model of a function returning a typed object literal is fundamentally simpler and more intuitive than the current abstraction of "using React to render a specific set of non-visual components." We're actually simplifying the conceptual burden by making the DSL's purpose more transparent.
Our current React-based approach has inadvertently created a walled garden that alienates developers without React experience. The functional approach democratizes content authoring by aligning with core TypeScript patterns that any developer can quickly grasp. A function that returns a strongly-typed object is a universal pattern across programming paradigms, making our DSL more accessible to a broader range of developers.
By owning our DSL implementation rather than piggybacking on a UI framework, we gain complete control over optimization, extensibility, and evolution. We're no longer constrained by React's design decisions or update cycle. The 31-63x performance improvement isn't just a technical metric – it represents the freedom to optimize specifically for our use case rather than accepting the compromises inherent in repurposing a general UI framework.
The functional approach isn't just about performance – it's about having the right tool for the job, reducing cognitive overhead, broadening developer accessibility, and establishing a foundation that can evolve with our needs rather than being constrained by external framework decisions.
5. Recommendations
We recommend implementing the custom React-like runtime. This balanced approach offers significant performance improvements while maintaining a familiar developer experience and minimizing migration effort.
The functional programming approach remains an option for future consideration, as it provides the highest performance improvements but would require more significant changes to development patterns.
Appendix
Comparison between writing FP DSL and React DSL
Functional Programming Approach:
React JSX Approach:
Beta Was this translation helpful? Give feedback.
All reactions