1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
[[!meta title="Juicemacs: Exploring Speculative JIT Compilation for ELisp in Java"]]
[[!meta copyright="Copyright © 2025 Kana"]]
[[!inline pages="internal(2025/info/juicemacs-nav)" raw="yes"]]
<!-- Initially generated with emacsconf-publish-talk-page and then left alone for manual editing -->
<!-- You can manually edit this file to update the abstract, add links, etc. --->
# Juicemacs: Exploring Speculative JIT Compilation for ELisp in Java
Kana (they/them) - IRC: kanakana, Blog: https://kyo.iroiro.party - ActivityPub: @kana@f.iroiro.party - Bluesky: @kana.iroiro.party, <mailto:kana@iroiro.party>
[[!inline pages="internal(2025/info/juicemacs-before)" raw="yes"]]
Just-in-time (JIT) compilation helps dynamic languages run fast, and
speculative compilation makes them run faster, as has been showcased
by JVMs, LuaJIT, JavaScript engines, and many more JIT runtimes.
However, Emacs native-compilation, despite its JIT compilation
(`native-comp-jit-compilation`), does not speculate about runtime
execution, making it effectively a JIT-ish AOT (ahead-of-time)
compiler. By introducing a speculative runtime for ELisp, we could
potentially improve ELisp performance even further, with many new
optimization opportunities.
Juicemacs <sup><a id="fnr.juicemacs" class="footref" href="#fn.juicemacs" role="doc-backlink">1</a></sup> is my work-in-progress toy project
re-implementing Emacs in Java. At its centre sits an ELisp JIT
runtime powered by Graal Truffle, a JIT interpreter framework based
on partial evaluation and Futamura projections. This talk will cover
the following along with some demonstrations:
- What is Juicemacs and its ambition? How compatible is it (or does
it plan to be) with GNU Emacs and how feature-complete is it now?
- What is speculative compilation? How is it useful for an ELisp JIT
runtime?
- What is Truffle and partial evaluation? What is needed if we are to
implement a speculative runtime in C without Truffle?
- How many interpreters are there in Emacs? How does Juicemacs
implement them?
- What JIT techniques does Juicemacs plan to explore? How can you
get involved?
# Footnotes
<sup><a id="fn.1" href="#fnr.1">1</a></sup> <https://codeberg.org/gudzpoz/Juicemacs>
Outline:
- Intro: Juicemacs
- Self-introduction
- Emacs `native-compile` versus modern JIT compilers
- Juicemacs: Yet another Emacs rewrite
- Demonstration: REPL, pbootstrap, pdump, elprop, ERT
- Speculative compilation
- What we talk about when we talk about JIT compilers
- Tired: JIT versus AOT
- Wired: With or without runtime information
- Speculative compilation
- Example: arithmetics
- Example: boxing elimination
- Graal+Truffle: a meta-compiler by partial evaluation
- ELisp JIT interpreters
- AST interpreter
- Macros
- Bytecode interpreter
- Regexp: slowish
- CCL: to be done
- Benchmarks
- Fun to be had (i.e., TODO & possible explorations)
- Transparent array-backed cons list
- Regexps
- Leaning on `native-compile` for LIMPLE IR
- Others
- GraalVM native image
- GUI
- Emacs dynamic module support
- How this could be implemented in C
- `transferToInterpreter`
- Bytecode approach
- Problems with the AST approach
- Closing Words
- Future of Juicemacs
- Future of GNU Emacs Lisp JIT
- Ways to contribute
About the speaker:
Hello! This is Kana, an Emacs hobbyist and Java lover from China. A
few years ago I discovered the Truffle JIT compilation framework and
have since hoped to implement a JIT runtime myself. Last year I
finally started implementing one for ELisp, called Juicemacs, and
have made some progress. In this talk I will share what I've learned
during the journey, including how three interpreters out of four (or
more?) in Emacs are implemented in Juicemacs and how speculative
compilation can make some optimizations possible.
[[!inline pages="internal(2025/info/juicemacs-after)" raw="yes"]]
[[!inline pages="internal(2025/info/juicemacs-nav)" raw="yes"]]
|