Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing a compiled Template using Marshal.dump fails after version 5.6.0 #1913

Open
rcugut opened this issue Feb 18, 2025 · 0 comments
Open

Comments

@rcugut
Copy link

rcugut commented Feb 18, 2025

Hello there,

Previous to release 5.6.0, up to 5.5.1, this code was possible (tested using ruby >= 3.2):

ct = Liquid::Template.parse(some_valid_liquid_string)

Marshal.dump(ct)  # this can be saved to memcache or disk

but with version >= 5.6.0, it fails with the error:

Marshal.dump: can't dump anonymous class #<Class:0x0000000153633cc0>  (TypeError)

By my investigation, this comes from the attribute @strainer_template which is now instantiated as an anonymous class, as part of the Environment instance.

I saw #760 conversation about the ability to cache a compiled template and as I understand it wasn't a main focus, it was something done in/before 2016 during hack days, but it worked up until 5.6.0, and it is als mentioned in the wiki as a strategy: https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#first-steps

The parse step creates a fully compiled template which can be re-used as often as you like. You can store it in memory or in a cache for faster rendering later.

Was this change intentional? Or is there any other way to cache (serialize) the compiled template?

Thanks!

PS: I did not do any elaborate benchmarks (yet) about compiling on each request vs fetching from cache, but IMO the way I see it is about moving work from IO (memcache) to CPU (re-compiling the template) on each request. If I could choose, I'd like the IO work better :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant