Posts tagged with optimize

Optimizing Eloquent: Accessor Caching and Value Objects in Laravel

www.harrisrafto.eu - submitted by Harris Raftopoulos

Laravel's accessor caching with shouldCache() boosts performance by preventing repetitive computations for expensive accessors. Additionally, you can work with complex data like addresses using value objects, and Laravel will auto-sync changes back to the model. This improves code efficiency and maintainability, especially for structured data.

Read more [www.harrisrafto.eu]

Join 9,500+ smart developers

Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Optimising Flare

flareapp.io

The laravel-data package is fantastic to work with, but it also adds a lot of complexity when outputting data. In this blog post, we will look at how we've improved the performance of the package and, thus, the complete Flare application.

Read more [flareapp.io]

Improving the performance of PhpStorm

PhpStorm is a fantastic editor. Unfortunately it can be quite slow. Brent, one of our developers at Spatie, blogged a few tips to make it run a bit faster. I've followed all his suggestions and PhpStorm now feels a bit more responsive.

I didn't start this post by writing my own thoughts, because I figured people were looking for some quick tips to speed of their IDE. As a PHP developer, I think that PhpStorm is such a powerful tool, which helps me to write good and maintainable code. I don't want it to stand in my way though, so good performance is an absolute requirement.

https://www.stitcher.io/blog/phpstorm-performance

Hopefully future versions of PhpStorm will be more performant out of the box.

Read more

Make your app fly with PHP OPcache

Recently this button to optimize PHP's OPcache was added to Laravel Forge.

If you were wondering what PHP OPcache is all about and what pressing this button does with your application, read this article Olav van Schie wrote on the subject a while ago.

Every time you execute a PHP script, the script needs to be compiled to byte code. OPcache leverages a cache for this bytecode, so the next time the same script is requested, it doesn’t have to recompile it. This can save some precious execution time, and thus make your app faster (and maybe save some server costs).

https://medium.com/appstract/make-your-laravel-app-fly-with-php-opcache-9948db2a5f93

Read more

A tool for making JavaScript code run faster

Even though I'don't like Facebook as a user, their amazing contributions to open source are something to be very grateful for. Last week they presented their new work in progress: Prepack.

Prepack is a tool that optimizes JavaScript source code: Computations that can be done at compile-time instead of run-time get eliminated. Prepack replaces the global code of a JavaScript bundle with equivalent code that is a simple sequence of assignments. This gets rid of most intermediate computations and object allocations.

https://prepack.io/

It's still in development, so best not use it in production environments yet.

Read more

Why objects (usually) use less memory than arrays in PHP

Because the properties for the object are predefined PHP no longer has to store the data in a hashtable, but instead can say that `$foo` is property 0, `$bar` is property 1, `$baz` is property 2 and then just store the properties in a three-element C array.

This means that PHP only needs one hashtable in the class that does the property-name to offset mapping and uses a memory-efficient C-array in the individual objects. Arrays on the other hand need the hashtable for every array.

https://gist.github.com/nikic/5015323

Read more