wagtail-deprecated / wagtail-react-streamfield

Powerful field for inserting multiple blocks with nesting. (NO LONGER MAINTAINED - See Wagtail 2.13 Release Notes)
https://wagtail.github.io/react-streamfield/public/
BSD 3-Clause "New" or "Revised" License
74 stars 23 forks source link

Provide an (optional) cache for block definitions on list block, stream block, and struct block #42

Closed robertsoakes closed 5 years ago

robertsoakes commented 5 years ago

This merge request provides an optional cache for block definitions. For complex stream fields with deeply nested blocks, this can speed up the load of the page editor (Wagtail admin) by one or two orders of magnitudes. The cache is enabled by using a BlockCacheStreamFieldPanel. The cache is created on the the binding of the model instance to the page/streamfield, and resets between page loads.

We have tested the system in two production systems, and have not yet seen any errors with other Wagtail React StreamField functionality: errors, notifications, and values work as expected.

The block definition hashing is controlled by the type of block, the icon, help text, and features (for rich text fields). I'm sure a more robust signature method will probably be needed at some point, but this is working well for our current use-cases.

BertrandBordage commented 5 years ago

Hi @robertsoakes and thanks for your contribution!

It’s very interesting, before you I didn’t know some people still had performance issues after switching to react-streamfield!

Your pull request is outdated, especially it’s not compatible with Wagtail 2.6. I will review it soon and see it’s not possible to do something simpler. To clarify, it seems a bit too complicated for just a caching, and I don’t want to add too much complexity to an already hard codebase just for a performance boost when the vast majority of users find it fast enough now.

BertrandBordage commented 5 years ago

I implemented a simpler version using cached_property with 136ae7df640b5eaf61dea088f1cd7b41037614ba. I saw a nice speed up on a rather simple StreamField that took 250-300 ms and now takes around 200 ms, sometimes even less :D

So it’s indeed nice to have for such a small change (adding a few decorators), and I hope it will be lightning fast on your complex architecture ;)