Posts tagged with performance

What's in store for PHP performance?

Jani Tarvainen explains where PHP is heading performance-wise.

PHP 7.0 was a leap in performance that came with very easy adoption. Simply verify compatibility with the version and upgrade your server environment. Speeding up many older architecture apps like WordPress and Mediawiki by a factor of two is a testament to backwards compatibility.

In 7.1, the language runtime will continue to make modest improvements, but bigger gains will have to wait. One of these opportunities for a bigger improvement is the JIT implementation that is now bound for PHP 8.0

https://www.symfony.fi/entry/whats-in-store-for-php-performance

Read more

Understanding generated columns

Generated columns where introduced in MySQL 5.7. In the latest post on her blog Gabriela D'Ávila explains the feature.

There are two types of Generated Columns: Virtual and Stored. ... Consider using virtual columns for data where changes happens in a significant number of times. The cost of a Virtual Column comes from reading a table constantly and the server has to compute every time what that column value will be. ... You should consider using Stored Columns for when the data doesn’t change significantly or at all after creation,

https://blog.gabriela.io/2016/10/17/understanding-generated-columns/

If you like the post, be sure to check out Gabriela's excellent talk at Laracon EU as well:

Read more

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

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

I Peeked Into My Node_Modules Directory And You Won’t Believe What Happened Next

Jordan Scales examined the contents of the node_modules directory a discovered a lot of junk.

While code bloat continues to slow down our websites, drain our batteries, and make “npm install” slow for a few seconds, many developers like myself have decided to carefully audit the dependencies we bring into our projects. It’s time we as a community stand up and say enough is enough, this community belongs to all of us, and not just a handful of JavaScript developers with great hair.

I decided to document my experiences in auditing my projects’ dependencies, and I hope you find the following information useful.

https://medium.com/friendship-dot-js/i-peeked-into-my-node-modules-directory-and-you-wont-believe-what-happened-next-b89f63d21558

Read more

Facebook's mobile device lab

As a user I've pretty much turned my back to Facebook, but boy must it be interesting to work at that scale. Here's how Facebook built their mobile device lab.

... We needed to be able to run tests on more than 2,000 mobile devices to account for all the combinations of device hardware, operating systems, and network connections that people use to connect on Facebook. Today, in our Prineville data center, we have a mobile device lab — outfitted with a custom-built rack — that allows us to run tests on thousands of phones. The process of building a lab in our data center wasn't a direct path, and we learned a lot along the way...

https://code.facebook.com/posts/300815046928882/the-mobile-device-lab-at-the-prineville-data-center/

Screen Shot 2016-07-15 at 21.23.13

I stumbled on this story via Bram.us. Subscribe to the RSS feed of that site if you haven't done so already.

Read more

How a 20mb data-set brought down a 14gb ElasticSearch cluster

Frank De Jonge, member of the PHP League and author/maintainer of Flysystem, was facing a world of pain with ElasticSearch. Luckily the story has an happy ending. Read all about his journey on his blog.

For a client project we are using ElasticSearch (ES) as one of our read-models. The use-case was pretty straight forward and the amount of data was super small. However, our problems were pretty big. It got to a point where we had to reboot our cluster periodically to prevent it from crashing. So, what was going on? Let's dig in.

https://blog.frankdejonge.nl/how-a-20mb-data-set-brought-down-a-14gb-elasticsearch-cluster/

Read more

Using MySQL's JSON columns in Laravel 5.3

Laravel 5.3, which will be released at this years Laracon US, has some new very handy functionality to work with MySQL 5.7 JSON columns. In a post on his site Matt Stauffer demonstrates the new API.

While Laravel has had the ability to cast your data to and from JSON since version 5.0, it was previously just a convenience—your data was still just stored in a TEXT field. But MySQL 5.7 introduced an actual JSON column type.

Laravel 5.3 introduces a simple syntax for lookups and updates based on the value of specific keys in your JSON columns.

https://mattstauffer.co/blog/new-json-column-where-and-update-syntax-in-laravel-5-3

If you're going to use this functionality, you should also read Mohamed Said's post on how to improve performance by using MySQL generated columns.

JSON columns cannot be indexed. You can work around this restriction by creating an index on a generated column that extracts a scalar value from the JSON column.

http://themsaid.com/laravel-mysql-json-colum-fast-lookup-20160709/

Read more

Best of Frontend United Conference 2016

A few weeks ago the Frontend United Conference was held in Ghent, Belgium. The entire development team at Spatie attended the conference. Though it certainly was fun to go to a conference with the entire team we were left a bit underwhelmed. Some of the talks were very short and some speakers seemed a bit unprepared.

The organisers have begun posting video's of all sessions to YouTube. In my opinion the following three talks rose above the rest.

1: Harry Roberts gave a talk were he demonstrated that programming best practices apply to writing CSS as well.

2: Christian Heillman talked about web obesity and gave a few tips on how to optimize the size of images.

3: Mathias Bynens showed how unicode support in JavaScript is broken and what common pitfalls are when working with special characters. Rather than just complaining about it, he offered some kick ass self-made solutions.

(the video for this session hasn't been posted yet, this is a video of the same talk at another conference)

Read more

Anonymous classes benchmarked

Mark Baker made some fascinating benchmarks on the performance of PHP 7's anonymous classes.

A week or so ago, I published an article entitled “In Search of an Anonymous Class Factory” about my efforts at writing a “factory” for PHP7’s new Anonymous Classes (extending a named concrete base class, and assigning Traits to it dynamically); and about how I subsequently discovered the expensive memory demands of my original factory code, and then rewrote it using a different and (hopefully) more memory-efficient approach.

Since then, I’ve run some tests for memory usage and timings to assess just how inefficient my first attempt at the factory code was, and whether the new version of the factory really was better than the original.

https://markbakeruk.net/2016/05/12/anonymous-class-factory-the-results-are-in/

Read more

Improving the speed of a MySQL import

A few weeks ago Gabriela D'Ávila helped a famous guy with getting an MySQL import down from 16 to 6 minutes. In a post on her blog she explains how that was done.

A few weeks ago my friend Frank de Jonge told me he managed to improve an import into a MySQL server down from more than 10 hours to 16 minutes. According to him it had something to do with one of the field types (too long fields to really small data) and the amount of indexes and constraints in the tables. We were talking about 1 million records here. He wondered if it was possible to make it even faster.

...

Turns out there are many ways of importing data into a database, it all depends where are you getting the data from and where you want to put it.

http://gabriela.io/blog/2016/05/17/fast-data-import-trick/

Read more

PHP Session Garbage Collection: The unknown performance bottleneck

Here is one performance setting in your PHP configuration you probably haven't thought about much before: How often does PHP perform random garbage collection of outdated session data in your application? Did you know that because of the shared nothing architecture PHP randomly cleans old session data whenever session_start() is called? An operation that is not necessarily cheap.
https://tideways.io/profiler/blog/php-session-garbage-collection-the-unknown-performance-bottleneck

Read more

Enable http2 on a Forge provisioned server

Added on 2016-04-28: newly provisioned Forge servers will now use http2 by default whenever you install an ssl certifcate.

Like mentioned in the post on how to upgrade PHP, I'm a big fan of Forge. By default sites provisioned by Forge use regular http. Let's learn how to enable http2.

The http2 protocol provides a lot of benefits over http. In short it'll make your website load much faster. If want to know how this protocol works under the hood watch this excellent video by Mattias Geniar or read this blogpost at Cloudflare. Here an interesting test by (again) Mattias that shows the potential speed improvements.

A prerequisite for using http2 is that you serve your website via an encrypted connection (note: this is not 100% true but virtually all major browsers won't support http2 via unencrypted connections). Thanks to LetsEncrypt you can get free ssl certificates. Watch this free video on Laracasts to learn how to install a LetsEncrypt certificate.

Support for http2 was introduced in Nginx 1.9.5. You can check the version number of your Nginx installation by running nginx -v. If you're on 1.9.5 or higher you're good. You just have to add http2 to a server block in the Nginx configuration:

server {
  listen 443 ssl http2;
  ...
}

The Chrome developer tools can be used to check if you're site is indeed using http2. The column "protocol" should display "h2".

http2

Don't be overwhelmed with sadness if you're running something below Nginx 1.9.5. Upgrading is easy! Only three instructions are needed to upgrade to, at the time of this writing, Nginx 1.9.14:

sudo add-apt-repository ppa:nginx/development
sudo apt-get update
sudo apt-get install nginx

Read more

Make Composer and npm lightning fast

Jack McDade, who designed the laravel.com and laracasts.com sites, shares some tips on how to make composer and npm much faster.

Whenever I run `composer install` or `npm install` I feel like an old man yelling at young punks to get off my lawn. Especially ever since `npm3`. I’ll save you the bitter diatribe and just get to the solution. But first, the problem.

Creating, distributing, maintaining, and consuming third-party dependencies was supposed to make us more productive and our lives easier. Instead, I feel like I spend more time waiting than coding.

So I dug and dug until I found solutions, as one does, and now I’m sharing them with you.

http://jackmcdade.com/blog/tired-of-waiting

Read more

Getting rid of Laravel models to improve performance

Marko Lekić explains how he used Blackfire.io to solve a performance problem in one of his long running Laravel console commands.

The command worked, but very slowly. We left it working like that for some time until we finished critical stuff in the system and had time to go back and refactor some slow running code.

We ran the command with Blackfire.io and saw some interesting information when we ordered functions by percentage of exclusive time.

https://medium.com/@marlek/getting-rid-of-laravel-models-to-improve-performance-of-the-command-blackfire-io-profiling-53884fa6573e

Read more