Jonathan Worthington has submitted the following grant proposal under the Perl 6 Core Development Fund.
Before we vote on this proposal we would like to get feedback and endorsements from the Perl community. Please leave feedback in the comments or send email with your comments to karen at perlfoundation.org.
Name: Jonathan Worthington (jnthn)
Project Title: Perl 6 Performance and Reliability Engineering
Improve both runtime and compiler performance of Rakudo Perl 6, with a focus on the MoarVM backend. At the same time, increase the robustness of the compiler, VM, and built-ins library.
Benefits to Perl 6 Development:
The Perl 6 Christmas release has eliminated "lack of a stable language" as an adoption blocker. The module ecosystem is steadily growing and documentation completeness improving, thanks to this language stability. Performance is now a key adoption blocker, and so improving performance is important to enabling Perl 6 to be used more widely. It's also important that this performance drive does not come at the cost of reliability. Rather, VM-level crashes - already relatively rare - should be further reduced, and high-impact bugs in the compiler and built-ins should be addressed.
Deliverable Elements / Project Details:
On the performance front, a huge range of improvements are possible throughout the stack - that is, in the VM, compiler, and built-ins. Of note, MoarVM has a fairly sophisticated dynamic optimization framework, but numerous optimizations have yet to be implemented since performance has not been the primary focus. Here are some examples of optimizations that I expect to work on over the course of the grant (including extensions):
- More aggressive lowering of lexical variables to locals in Rakudo's optimizer, which can decrease memory use and enable/simplify numerous other optimizations
- Making object accessors and object construction cheaper
- Decreasing the cost of invocation (that is, calling subs/methods/closures)
- Decreasing the GC and cloning costs of closures, and making the MoarVM dynamic optimizer far more aware of them
- Better JIT compilation of Int math operations
- Smarter inlining, especially of simple control-flow-free functions
- Optimizing out box/unbox sequences, as well as taking/using native references
- Performing GC finalization on a background thread, to decrease pause times
- Performing dynamic optimization on a background thread, so it does not pause code execution
awaitnon-blocking, to greatly improve scalability of async code
- Improving ThreadPoolScheduler, so it picks a smarter number of threads
- Improving I/O performance
- Better optimization and code-gen for tokens and regexes
- Decreasing the number of times characters are visited during parsing
- Implementing escape analysis, to reduce GC overhead
- Looking into more effective parallel GC synchronization mechanisms
Since I intend to look to Perl 6 users' examples of unperformant programs to drive my work, the exact prioritization of these tasks will likely not match what is listed above, and other more pressing performance issues will likely be discovered and addressed along the way also.
It is also important we are able to analyze performance and understand it. Right now, there is an instrumenting profiler. That's useful in so far as it produces detailed information, capturing every single call and allocation, along with statistics on inlining, optimization, and JIT compilation. However, for anything besides micro-benchmarks, it produces vast amounts of data - into the hundreds of megabytes. That is to say, it's more useful for the kind of in-depth analysis a VM engineer wants to do having isolated a performance issue than it is for finding the hotspots in a larger application. It also isn't so useful for getting a good picture of how memory is being used. So, I propose to build as part of this grant:
- A sampling profiler, which is better suited to analyzing applications. This would likely become the default, user-facing profiler.
- A heap profiler, for getting a better overview of what's in memory.
On the reliability track, a lot of the focus will go on picking off the most serious or impacting bug reports from the RT queue. Key candidates are:
- Anything involving a segfault, bus error, etc.
- Anything where the compiler reports an internal error
- Memory leaks
- Regressions that impact modules in the ecosystem
- Bugs that trip Perl 6 users up regularly
I will also write regression tests to cover fixed issues.
I intend to work 40-50 hours a month on this grant. Working on performance and reliability is, by nature, open-ended: there's always more that can be done. Therefore, so long as I feel the topics this grant addresses are the best way I can serve the Perl 6 project, I will request extensions of this grant every 2-3 months. Each time I will report what has been achieved, and indicate where I expect to focus next. This way, the wider community can also provide their views on whether the focus is correct on a regular basis also.
I'm the current architect for both MoarVM and the Rakudo Perl 6 compiler. In MoarVM, I designed and implemented large parts of the dynamic optimization infrastructure, mentored its JIT implementation, and built the current instrumenting profiler (in the space of 2-3 days!) In Rakudo, I've been a key contributor to many parts of the codebase, implementing numerous language features and fixing hundreds of bugs. I also played a leading role in the design of Perl 6's concurrency features. Between the Rakudo, NQP and MoarVM repositories I have made just short of 12,000 commits at the time of writing.
Endorsed by: Moritz Lenz
$50 USD / Hour * initial 200 hours = $10,000 USD
Suggestions for Grant Manager: Will Coleda