Somehow syntax error has occured.
t-matsudate opened this issue · 2 comments
I tried to use hiccup 2.0.0-alpha2 with following code:
(ns my-project.handler
(:require
[ring.util.response :refer [response]]
[hiccup.page :refer [html5]]))
(defn- hoge-view [...]
(html5
(call-a-vector-to-have-17-element-meta-tags)
[:body
; up to 10 nests, arround 40 elements.
]))
(defn hoge-handler
[request]
(response (hoge-view ...)))
Then, somehow following syntax error has occured:
Exception in thread "main" Syntax error compiling fn* at (my_project/handler.clj:xxx:y).
...
Caused by: java.lang.IndexOutOfBoundsException: Method code too large!
Preconditions:
- Using: OpenJDK11, Clojure 1.10, Ring 1.7.1 and Hiccup 2.0.0-alpha2
- In hiccup 1.0.5, this error has not occured.
- In hiccup 2.0.0-alpha2, this error has occured.
What is occuring in hiccup 2.0.0-alpha?
Hiccup pre-compiles the data structure into code in order to speed up execution. It looks like you're hitting the inbuild JVM limits of how much code can be in a single method.
It probably doesn't show in earlier versions because Hiccup 2.0 supports more functionality, and therefore happens to produce more code in your particular case. Hiccup 1.0 would run into the same problem, just at a later point.
If performance isn't an issue, you can wrap your code in a function:
(defn html5* [& data]
(hiccup/html5 data))
This ensures pre-compilation isn't used. Otherwise, split your Hiccup data into smaller functions. It's generally more idiomatic to write smaller Clojure functions than larger ones.
In future we could potentially solve this by dividing code into functions automatically, but that will need a PR and some significant work.
Thank you for telling how to solve this issue!
I'll try to split the code making the html vectors more smaller, and will retry to use hiccup 2.0.0-alpha.