A quick fix on ORM usage

By Christophe Dujarric, on Nov 19, 2015

The following article as written by Daniel Kubitza (@HydraxSkarrag) during the #FireUpMyMac contest. Find the original here.

He managed to find and resolve an issue in a few minutes with Blackfire, where it could have otherwise taken a few month before he would have understood where the issue was.

Now nearly a year ago I was put on new task:

Optimize the performance of an application I did not know before.
This was not a really a new tasks for me, but I was a little worried about the available tools outside. They work, but it is mostly hard to find the performance issue.
During this time Blackfire was already in beta and in the end of November a colleague and me got access. So I tried the same also with Blackfire. In the end I could not find anything for this project. But I really liked Blackfire.

Some month later I started to profile the performance of the homepage of a different project. Here I could very quickly find some issues and within one day I was able to double the performance of the homepage. To bad that I don’t have those profiles anymore.

On my current project we are mostly serving an API for mobile devices. So I took one day to profile every API endpoint. First I could not find any specific, but after I added 20.000 test items (and also over 6000 items are related to my test user) the performance of one Endpoint dropped to around 3.x seconds.

Here is to bad profile for the endpoint:
(note: screenshot say 18s but during this time the importer was still running)

Spot (what you can see in the screenshot) is the small ORM we use in our project. I quickly realized that there where 6426 entities created – which is definitely wrong :).

The issue was quickly found. All related items where fetched and counted (picardpalm) instead of using a real count query. So the fix for this issue was also very quick:

The result with the next profiling:

208ms instead of 3.x seconds.

The direct comparison:

Without Blackfire and the testdata we would not have found this problem until someone hits the amount of items which could took some month.

If you did not work with Blackfire: Try it out. Its really worth the time you invest. And it offers much more I just described here.

Christophe Dujarric

Christophe is the Product guy at Blackfire/SensioLabs. He has been working in several start-up companies, helping them to make and sell products out of technologies. He’s involved in every step of the product’s lifecycle, from strategy to design and sales, and loves to coach on product management methods.