When I started refactoring Scala's actor library, I really had several goals:
- Reduce the coupling within the library so that the implementation can be more easily extended and customized
- Create a more transparent and "programmer friendly" actor implementation
- Improve performance of various use cases
- Make actors that interact better with their environment, particularly non-actor code
- Maintain API compatibility with the existing library to the maximum extent practical
Thus far I've done my work by completely overhauling the Actor trait directly in the library. While I have plans for how this will reduce coupling, the haven't come to fruition yet. I think my state machine model is considerably more transparent and programmer friendly than the current implementation. The state an actor in is always clear, transition are reasonably well defined, and performing correct locking and unlocking is now pretty straight forward. I've substantially improved the performance of event-based actors for the common case where an actor loops while it receives messages until some termination criterion is reached. I haven't done anything with making them interact better with their environment yet, as I believe Philipp Haller is in the process of incorporating some changes for which I submitted patches several months back that will help considerably (he doesn't appear to be using the patches directly, but the changes I've seen are close enough).
A few days ago David MacIver asked me a couple interesting questions on IRC:
- Have you considered using Kilim?
- Have you looked at the continuations support that appears to be emerging as a compiler plugin?
Using Kilim would almost certainly disqualify the changes I'm making from incorporation into the standard library because of the external dependency on a prerelease framework that uses bytecode manipulation, and I don't think the fledgling continuation support is mature enough to experiment with yet (or maybe just not well documented enough yet, who knows...). That being said, both of these would be interesting avenues of development. Event based actors rely heavily on continuations, and the performance of those continuations has a substantial effect on the performance of the actors. Ultimately a properly decoupled implementation would allow someone to build an API compatible actor implementation on either of these technologies, or something else entirely.
I also received a recent nudge on the mailing list, when someone pointed out that it would be easier to experiment with my library if it was in it's own package. I somewhat disagree with that. It would be easier to experiment with it if you didn't have to do an entire build of the Scala distribution that has my code in it, and unfortunately for the foreseeable future I'm going to be depending on both code that is being committed into the trunk and on the ability to modify said code. Also, the way I have it setup today, if someone wanted to test their Scala application/library/framework against my state-based actors, they would just have to pull my Mercurial repository, build it, and rebuild against the resulting distribution. On the downside, it's a pain to do side-by-side comparisons between the two implementations, because you have to switch distributions and rebuild every time.
That being said, decoupling is one of my primary goals, and Martin & Company have already set the precedence of doing major work in a separate package with their efforts on redesigning the Scala collections library. So as soon as I finish up some of my immediate tasks and have a good build again (I'm in the middle of redesigning the control flow pattern to minimize the stack size when exceptions are thrown), I'm going to push most of the public and protected interface on Actor into a new trait that will be between Actor and AbstractActor as abstract methods, move my code out of scala.actors and into scalax.actors in my own directory. I definitely keep it within the same repository as the Scala distribution code, and will probably just make another directory for it. This means I'll have to mess with Sabbus to add my portion to the build, which won't be fun, but shouldn't be too hard. I'm sure there's going to be a lot more to do to extract it out, so I'll be adding items to my issues list as I think of them.
The end result should be my state based actors and the existing actors being able to live side-by-side and interact with one another in the same program. Assuming I can at least get some patches into the main library, it will also mean that the future of my work will not be dependent on being incorporated into the standard distribution. If it is, great, if not, I can distribute it separately. I would have done this from the start, but initially I was highly dependent on the existing code and infrastructure into order to get something working reasonably quickly, and to be able to smoke it out to see if it indeed worked. Back in December I was basically breaking partest with every change. But now things are reasonably stable, I rarely break partest, and I don't think it will take much for my code to be able to stand on its own.
So what does everyone think? Is this a good direction to head in?Sphere: Related Content