5 ms·
Pycket: A Tracing JIT For a Functional Language (2015) [pdf]
- mncharity 8y agohttps://github.com/pycket/pycket https://github.com/pycket/pycket - development is active. > There are currently two different modes of evaluation that we refer as OLD and NEW. The NEW Pycket uses linklets and bootstraps the Racket using the expander linklet exported by Racket (version 7+). The OLD Pycket, on the other hand, uses Racket's binary to fully expand the program and generates json asts and evaluates them. More on linklets: https://docs.racket-lang.org/reference/linklets.html https://docs.racket-lang.org/reference/linklets.html Status of Racket-on-Chez (2018-Jan): http://blog.racket-lang.org/2018/01/racket-on-chez-status.html http://blog.racket-lang.org/2018/01/racket-on-chez-status.ht... Back in 2015, a previous thread[2] mentioned a Pixie issue[1], which was closed with "I worked a ton on this, but ran into time issues before the Strangloop conference. At Strangeloop I got talking to one of the authors of Pycket. Unfortunately it sounds like their implementation isn't much better than mine. The amount of load that is put on the JIT due to this sort of interpreter is quite large. In short, I'd rather have a mutable fast interpreter than a immutable mostly fast interpreter. Shelving this work for now. The PR will still exist, but I'm not convinced the features are worth the cost." Pixie's most-recent commit seems a year ago. My brief unsuccessful search for current Pycket benchmarks did turn up this[3] 2017 thread/paper on the Nash (Guile) tracing JIT. [1] https://github.com/pixie-lang/pixie/issues/312 https://github.com/pixie-lang/pixie/issues/312 [2] https://news.ycombinator.com/item?id=9545628 https://news.ycombinator.com/item?id=9545628 [3] https://news.ycombinator.com/item?id=13773796 https://news.ycombinator.com/item?id=13773796
- sabauma 8y agoI haven't checked in on the development of Pycket in a bit, but much of the recent work has gone into supporting linklets. Last I checked, the performance story for the Scheme and Shootout benchmarks used in the paper haven't changed much. There are some benchmarks which evaluate Pycket's performance when applied to gradual typing [1]. Pycket does a pretty good job of optimizing the overheads of gradual typing (or at least Racket's implementation strategy), though it by no means eliminates the performance costs. [1] https://dl.acm.org/citation.cfm?id=3133878 https://dl.acm.org/citation.cfm?id=3133878
- nielsbot 8y agoWonder how this compares to mainstream JS JITs? Reading just a bit, they say Pycket includes general features needed for languages like JS, but sounds like someone would need to implement a JS front end. Any volunteers?
- ufo 8y agoRPython is a framework for building trace-based JITs. Its selling point is that it automatically produces a JIT from a high-level specification of your language (basically, you would implement an interpreter for JS in RPython and then the framework would spit out a JIT) In JavaScript land there is less space for high level frameworks because browser vendors are willing to throw thousands of man-hours into JIT development. They are willing to go through this trouble to avoid the runtime overhead of meta tracing. Additionally, JS JITs have moved towards a more method based than trace based approach over the years, for whatever reason.
- eggy 8y agoWith the Racket core currently being re-written in Chez Scheme, how will this affect Pycket? Will regular Racket become fast enough to preclude using Pycket?
- ufo 8y agoOne of the things that the Pycket team has been trying to do is use JIT compilation to cut down on the runtime cost of Racket's contract system. This is not an area chez scheme would be able to compete with. I don't really know what is the current state of pycket other than that though.
- samth 8y agoPerformance varies a lot in Racket-on-Chez. For some programs, such as tight loops over simple data, Chez provides a lot of the same benefit as Pycket, but Pycket is often still faster. Here's a simple loop that sums numbers from 1 to 100000000, with timings for all three variants of Racket: [samth@huor:~/sw/plt (master) plt] pycket-c -t count.rkt cpu time: 83 real time: 83 gc time: 0 4999999950000000 [samth@huor:~/sw/plt (master) plt] racket -t count.rkt cpu time: 226 real time: 227 gc time: 0 4999999950000000 [samth@huor:~/sw/plt (master) plt] racketcs -t count.rkt cpu time: 170 real time: 174 gc time: 2 4999999950000000 Chez is faster than regular Racket, but not as fast as Pycket. However, other programs the difference is much bigger. If we use generic iteration instead of type-specializing it, we get these numbers: [samth@huor:~/sw/plt (master) plt] racket -t count.rkt cpu time: 2883 real time: 2882 gc time: 0 4999999950000000 [samth@huor:~/sw/plt (master) plt] racketcs -t count.rkt cpu time: 1266 real time: 1266 gc time: 0 4999999950000000 [samth@huor:~/sw/plt (master) plt] pycket-c -t count.rkt cpu time: 74 real time: 74 gc time: 0 4999999950000000 Finally, on programs with contracts and gradual types, one of our focuses for Pycket, Racket-on-Chez is currently substantially slower than the current Racket VM.
- samth 8y agoSource code here: https://gist.github.com/92ed7836508fe15b1e58f840a8d3a534 https://gist.github.com/92ed7836508fe15b1e58f840a8d3a534
- shawn 8y agoI've been thinking along these lines as well. One of my dirty secrets is that I'm jealous of Rust's zero cost iterators. I want those in JS and Lua. One way to get them is to write an interpreter for a specialized subset of the language, and generate traces for each part of your program that uses e.g. map and reduce. It seems possible to specialize the generated code so that the overhead is essentially zero cost, but I haven't thought about it deeply enough yet. There must be a way to get Rust's zero cost abstractions without the steep penalty of static typing plus borrow checking annotations.
- ufo 8y agoMacros, perhaps? Tracing JITs actually can have a hard time with map and reduce because they can't always tell that different calls to map should be compiled with different traces. If you try to use the same trace for map(f) and map(g) you are going to fall out of the trace often. For an example of this issue coming up see https://github.com/luafun/luafun/issues/32 https://github.com/luafun/luafun/issues/32
- shawn 8y agoWhoa. Why does that happen? The first call does indeed compile down to a tight loop of around 10 instructions. However, the second call compiles down to around 62 instructions - even though it is exactly the same code! That seems like a bug rather than a consequence of tracing JITs, isn't it? Macros are one possibility, but they require global knowledge at compile time, which is at odds with the dynamic nature of scripting languages. Suppose you want to write a function `f` which takes some object `x` and calls `str(x)` on it. If you know the type of `x` at compile time, it's a simple matter to substitute `str(x)` with `x.str()`, if you know it contains a `str()` method. The other code would look like this: (define-global str (x) (if (and (obj? x) (get x 'str)) (call (get x 'str)) ... else stringify `x` as normal )) i.e. you'd have to write a `str` function that checks the type of `x` at runtime, incurring a cost. A strongly typed language is one possibility, but it seems like we could do better by tracing at runtime. When you know that `x` has a method `.str()`, shouldn't it be possible to replace all instances of `str(x)` with `x.str()` at the call sites themselves? Just recompile all the functions that call `str(x)`. Then you can even inline the str() method's code directly into the call site.
- xfer 8y agoSaw this benchmark comparison between RPython vs Graal the other day: http://stefan-marr.de/papers/oopsla-marr-ducasse-meta-tracing-vs-partial-evaluation/ http://stefan-marr.de/papers/oopsla-marr-ducasse-meta-tracin... Is there a scheme implementation on graal vm?