Grant Proposal: Raku Dispatch and Compiler Improvements
Sun, 23-May-2021 by
Jason A. Crome
edit post
# Name
Jonathan Worthington
# Synopsis
I currently have two ongoing grants:
* A Raku performance and reliability grant, under which almost all the time is
currently dedicated to implementing a new generalized dispatch mechanism. Progress
so far indicate it will offer both performance improvements and simplify future
development.
* A RakuAST grant, which involves implementing a user-facing document object model
for the Raku programming language. This will provide a foundation for macros and
a number of other meta-programming features. A new compiler frontend is being
developed in parallel with the new AST.
The first of these two grants is near the end of its funded hours. Therefore, this
grant application is most immediately for funds to continue with, and bring to
completion, the new dispatch mechanism, such that it can be delivered in MoarVM and
Rakudo releases. That grant operates on the basis of hours worked, and I'm requesting
this grant on the same basis.
The second of the two has some way to run, but its goal is to reach 80% coverage
of the specification test suite using the new RakuAST-based compiler frontend.
Further work will be needed beyond that, to exploit the new opportunities for
better quality code generation by the compiler as well as to make it robust
enough to become the default compiler frontend for Rakudo. Therefore, the hours
left over on this grant beyond the delivery of the new dispatch mechanism would
be allocated to furthering that effort.
# Benefits to Raku Development
Early benchmarking of the new dispatch mechanism suggests it will bring significant
performance improvements to a number of Raku language features, and potentially
improve even on areas that are quite well optimized today. It will also simplify
the overall architecture of the Rakudo/MoarVM stack, eliminating a number of special
cases and easing further improvements. With performance still being one of the key
weak areas, improvements in this area are important. We've come a long way, but it is
not yet enough for some applications. Performance aside, the new dispatch mechanism
also stands to simplify the development of some future Raku features, and to create
new optimization opportunities.
RakuAST brings about the first major overhaul of the Rakudo compiler frontend in a
decade. That's a lot of time to have learned better ways to do things. On top of
that, macros remain one of the main undelivered promises of the Raku language.
RakuAST provides the foundation for delivering useful macros that can solve real
problems, as well as providing an API to the Raku language that could have many
further applications, such as implementing linters and even a Language Server
Protocol implementation to improve editor support.
# Project Details
I have written a [blog post about the new dispatch mechanism](https://6guts.wordpress.com/2021/03/15/towards-a-new-general-dispatch-mechanism-in-moarvm/),
which provides an overview of what it is about. The key remaining tasks at this
point are:
1. Finish implementing all of the Rakudo dispatch semantics atop of the new dispatch
mechanism. This work is currently around 80% complete.
2. Switch all dispatch in Rakudo to use the new general dispatch mechanism.
3. Fix everything needed to get the specification test suite passing and the module
ecosystem looking in good shape.
4. Make the MoarVM specializer able to work more completely with the new dispatch
mechanism, so we get all of the inlining and other benefits back.
5. Switch NQP to use the new dispatch mechanism too.
6. Eliminate lots of now-unused code in MoarVM, along with the current method
caches, which shall no longer be needed.
In theory, we can "ship it" before doing steps 5 and 6. In practice, we'll see
if that makes sense. I expect all of these to be completed within the hours
requested on this grant.
Similarly, I've given a [talk that lays out the rationale for RakuAST](https://jnthn.net/papers/2020-cic-rakuast.pdf).
I won't work on it under this grant until the goals of the previous one have
been reached. However, at that point the remaining work shall be:
* Get the new RakuAST-based compiler frontend fully passing the specification test
suite
* Ensure that the optimizations performed by the current compiler frontend are
also achieved by the RakuAST-based one, so we can say it produces equivalent or
better bytecode than is achieved today
* Resolve any other blockers to switching over to using RakuAST as the new compiler
frontend
The hours requested under this grant may not be sufficient to complete all of these
steps, however there should at that point be a more detailed picture of what work
remains to be done.
# Project Schedule
I expect to have exhausted the hours allocated to the current Raku Performance and
Reliability grant by the end of April 2021, and so would be ready to begin working
under this grant right away.
I aim for the July or August releases of Rakudo and MoarVM to use the new dispatch
mechanism, which means merging it shortly after either the June or the July release
to maximize testing time.
# Bio
I am the founder and architect of MoarVM, the most popular runtime for Raku users,
and the architect of the Rakudo compiler. I have contributed to the implementation
of numerous Raku language features, and played a key role in the design of the
concurrent and parallel aspects of the language. I hold a degree in Computer
Science from the University of Cambridge, and actively work in the field of
developer tooling and compilation.
# Amount requested
200 hours * $60 USD / hour = $12,000 USD
# Endorsed By
The full Raku Steering Council (see comments on https://gist.github.com/jnthn/e8d62a0452e9fc24f7eb445139b1ff76)
Comments (3)
I think that both the new dispatch mechanism and RakuAST have the potential to be game changers.
While those features may not be enough to get people to flock to Raku by themselves; they may be enough to enable The Next Big Thing™. Which may have the potential to get people to flock to Raku. (Think Ruby on Rails but better.)
I also think that jnthn is the single best hope for getting those features finished in the near future. I'm sure we have other people capable of finishing those features, but the features are more fully formed in jnthn's mind than in any other person.
I honestly think that this may be a defining moment for the future of Raku.
I had the pleasure to work with Jonathan on some projects during the last years. Whatever he delivered was well thought through and cleanly implemented. While this was on a much less mind-blowing level than his work on MoarVM, I have no doubt that he will do again a great job on the proposed work. In addition, he also blogs about his work and it is always a good read, even when my understanding of the MoarVM internals is very limited.
The work proposed is a continuation of what he started a while ago and coming to a completion soon. I am very much looking forward to the first Rakudo release including the new code and also on the new things that will be possible once completed (Macros, easier optimizations, etc).
Please fund this project asap.
+1 jnthn has always produced great thing and I very much look forward to seeing the new dispatch and RakuAST work land.