Hello
I have been experiencing some issues like the slow switching between pages, after updating Piranha.
Previously I was using the synchronous API on version 5.4 and there was no problem. Now, a single page reload takes 12 seconds and going to another page takes half of this.

Do you have any suggestions on how can this be fixed?
Thank you in advance.
Best regards,
Chris
Hi there @aneff-official The main difference between version 6.x and the versions before it is
Pages containing a lot of references to other content using PageField and/or PostField could experience a decrease in performance as the referenced entities will be loaded from database. The basic PageField and PostField will be updated in the upcoming release to load a PostInfo/PageInfo model which are cached. Until then if this is affecting you, you can register custom fields doing this.
Archive pages operating on the standard ArchivePage could experience a decrease in performance as all posts will be loaded from database if they are dynamic. This can be fixed by specifying the type of the archive to load, please refer to http://piranhacms.org/docs/basics/how-to-setup-content/archive-page-types
After reported issues on cached data being corrupted (due to threads changing the models returned from the cache) we decided to clone the objects before returning them. This however takes a little bit of time, so if you know what you're doing your can easily revert to the old behavior by adding your own cache implementation without the cloning. Use the default implementation as reference: https://github.com/PiranhaCMS/piranha.core/blob/version/v6.1/core/Piranha/Cache/MemoryCache.cs#L42 (The only change needed is to remove DeepClone).
If you need more information or help I will probably need more detailed information about the pages that you have noticed performance drops in and how they are implemented.
Best regards
H氓kan
Hi again,
So,
PageField
I have maybe less than 10 on the home page (header&footer links + main). I don't know if that is "a lot", but I will look forward to get the next version's fix.
Archive
I am using the following:
var model = await api.Pages.GetByIdAsync<BlogArchive<PostBase>>(id);
model.Archive = await api.Archives.GetByIdAsync<PostBase>(...);
So there shouldn't be a problem? I have 2 different types of Posts and 15 posts in total (loading only on the Index page).
MemoryCache
I saw where this is, but if that is in your files, do I need to clone the whole project or there is a way to override it?
Thank you for your fast answer, I appreciate it.
Chris
The main page will load from cache without any processing, however your 10 PageFields will each require loading the pages from database and then transforming them from normalized data to the model. This is not good for a page that will get a lot of hits. @filipjansson is working on a Gist with a PageField that uses PageInfo instead of DynamicPage. Please note that PageInfo does not contain regions & blocks, if you want full models your should change the code to using PageBase instead.
Sounds good!
Simply add a new class to your project using the provided code as reference, for example MyMemoryCache.cs. Then instead of calling services.UsePiranhaMemoryCache() you call:
services.AddSingleton<Piranha.ICache, MyMemoryCache>()
Hi @aneff-official!
Here is the gist H氓kan mentioned.
https://gist.github.com/filipjansson/0f9db48874cc5427f65cf0461f0415bc
BR
Thank you!
I will try this now :-)
P.S. Looking forward to seeing the new major version of Piranha
Chris
Hi there @aneff-official Just checking in to see if got it sorted out!
Hi!
Sorry for the late reply. I will add another comment in a few hours after I am finished with the tests, but unfortunately it looks like the suggestions do not help much :(
Chris
@filipjansson
Your PageInfoField improved the speed, thank you. It is not as fast as it used to be, but now at least is bearable.
Thank you both for your time :)
Great! What difference are we talking about now compared to the previous version? You could also implement memory cache without clone which will reduce the time it takes for the models to be returned from cache!
Hi
Were you talking about DeepClone or about some other Cloning?
I have done all of your suggestions. The PageInfoField lowers the page load with around 10 seconds and removing the DeepClone from MemoryCache lowers it with 2-3 additional seconds.

I know it depends on many things, but roughly speaking the fix has reduced the loading time with 13s. Would you please explain why is this not part of the original code?
Thank you,
Chris
The PageField was kept as is for backwards compatibility, but will be replaced in 7.0.
The cache implementation was a safety measure as users were destroying the cache instances by assuming they are new copies (which is a logical assumption).
In 7.0 there will be multiple instances of all cache services, one with clone and one without cloning.
So basically all the stuff you added will be out of the box functionality in 7.0, but is implemented the way it is in 6.0 for compatibility.
Best regards
And it all depends on how you鈥檙e using it. The official PiranhaCMS site runs 6.1 without any of these fixes without any negative impact, but in your case where you have a lot of referenced content from your page which causes a lot of operations there was a huge difference in performance!
I agree with you!
Thank you and keep up the good work.
Regards,
Chris
Clone is now removed as default choice in 7.0. Memory caches can now be registered with:
services.AddPiranhaMemoryCache(clone: true);
services.AddPiranhaSimpleCache(clone: true);
Okay, I guess you can close this issue now :)