Eloquent vs. Doctrine ORM on PostgreSQL

In my benchmark, Eloquent read 10,000 objects in 154.7 ms and Doctrine took 229.5 ms. Repeated lookups by ID reversed the result. Doctrine finished in 32.1 ms and Eloquent took 629.6 ms.
Some colleagues said that Eloquent was slow, so they preferred to start with Doctrine. Active Record, Data Mapper, and magic attributes kept coming up. I wanted to see which operations made those differences visible, so I set up a single PostgreSQL database and measured reads, relationship traversal, and writes with both ORMs.
How I ran the benchmark
The benchmark used Docker on one machine. PHP 8.4.25 ran with OPcache on and JIT off, with PostgreSQL 17.11 in a neighboring container. I ran Eloquent from Laravel 13 (illuminate/database 13.32.0) through Capsule without bootstrapping Laravel. Doctrine ORM 3.7.1 ran in production mode with DBAL 4.4.4, APCu for metadata and query caches, and native PHP lazy objects. The second-level cache was off. I kept model events and casts on in Eloquent and change tracking on in Doctrine.
Both ORMs used the same tables and foreign key indexes. I seeded 10,000 users, ten posts per user, and five comments per post, for a total of 610,000 rows. I ran ANALYZE after seeding.
Each variant had three warmup iterations followed by 15 measured iterations, or five to seven for the heavier scenarios. The tables report the median of the three run medians. Where the harness compared checksums, they matched. I measured database access time separately with DB::listen() in Eloquent and DBAL middleware in Doctrine. The memory figures are peaks reported by PHP in a separate run of each variant.
Reading rows into objects
Each ORM loaded users with a single query, then iterated over the result and summed their ratings.
| Variant | 1,000 objects | 10,000 objects | Peak memory at 10,000 |
|---|---|---|---|
| Eloquent | 15.8 ms | 154.7 ms | 16.1 MiB |
| Doctrine | 21.8 ms | 229.5 ms | 25.6 MiB |
At 10,000 rows, Eloquent took about a third less time and used 37% less memory. The measurement includes the query, hydration, and iteration. During hydration, Doctrine registers each entity in its identity map and takes a snapshot of the fields for change tracking. Eloquent fills in the model's attributes and keeps their original values on the model itself.
For a report or export, I also measured ways to read the rows without creating models or entities.
| ORM | Models or entities | Read mode | Time in that mode |
|---|---|---|---|
| Eloquent | 154.7 ms | toBase()->get() | 30.7 ms |
| Doctrine | 229.5 ms | getArrayResult() | 143.0 ms |
toBase()->get() returned plain objects and cut Eloquent's time by 80%. getArrayResult() used an array hydrator and cut Doctrine's time by 38%. Each percentage compares two paths in the same ORM. The two read modes return different data structures.
The cost of reading one field
I read the same field a million times on a model and on an entity. Each measurement included one initial lookup by ID.
| Access path | Total time including lookup | Approximate time per access |
|---|---|---|
Eloquent, $model->name | 2,069.6 ms | ≈2,070 ns |
Eloquent, $model->getAttributes()['name'] | 143.7 ms | ≈144 ns |
Doctrine, $entity->name | 8.9 ms | ≈9 ns |
The microbenchmark produced a gap of about 230×. Doctrine reads a public property. Eloquent goes through __get() and getAttribute(), which determine how to handle the attribute. The field in this test had no accessor. getAttributes() exposes the internal array. For a field with a cast or an accessor, the value in the array can differ from the one returned by property access.
Repeated lookups and stale data
Within one iteration I called find() for the same 100 user IDs ten times.
| Variant | Time | Queries | Database access time |
|---|---|---|---|
| Eloquent | 629.6 ms | 1,000 | 518.5 ms |
| Doctrine | 32.1 ms | 100 | 25.7 ms |
With the same EntityManager, Doctrine returned objects from the identity map on subsequent calls. Eloquent issued a query on every call. Doctrine took about one-twentieth of the time, with database access accounting for most of the gap.
I then loaded a post with views = 1 and used a single query to set views = 777 on ten posts. The object already loaded in each test kept the old value. Then I called find() again.
| Value read | Eloquent bulk update() | Doctrine DQL UPDATE |
|---|---|---|
| In the previously loaded object | 1 | 1 |
Returned by another call to find() | 777 | 1 |
find() after a bulk update
PostgreSQL stores views = 777. Both loaded objects still hold views = 1.
-
find()Sends aSELECTto PostgreSQL. -
New model
views = 777
-
find()Returns the same object from the identity map withviews = 1. -
refresh()Reads the row from PostgreSQL. The same object now holdsviews = 777.
Doctrine returned the same object. After refresh(), it showed 777. If a decision in the same operation depends on the updated value, refresh the managed entity before reading it.
One query or two
I compared ways of loading posts for 500 users. The two-query Doctrine variant loaded the users and posts separately and summed the views directly from the list of posts. I traversed the posts through each user's relationship in the with() and fetch join variants.
| Variant | Time | Queries | Peak memory |
|---|---|---|---|
Eloquent, with('posts') | 125.5 ms | 2 | 14.3 MiB |
| Doctrine, two separate queries | 148.7 ms | 2 | 20.5 MiB |
| Doctrine, fetch join | 196.0 ms | 1 | 20.7 MiB |
The JOIN result repeats the user's columns for each post, and the hydrator uses those rows to assemble the object graph. The two-query variant skips that work. If the application needs the object graph, include the cost of assembling it when comparing the two approaches.
For user → posts → comments over 50 users, Eloquent used with('posts.comments') to run three queries in 65.4 ms. Doctrine ran one in 121.7 ms with a two-level fetch join. Lazy loading took 551 queries with each ORM, finishing in 395.0 ms with Eloquent and 249.5 ms with Doctrine.
The database ran on the same machine. With higher network latency, an extra query can cost more than transferring repeated data in the JOIN result.
Writes and the size of the unit of work
I loaded the objects ahead of time, changed one field on one of them, and saved it. The timer covered changing the field, saving it, and rolling back the test transaction. It started after I loaded the objects.
| Variant | Time | Operations counted |
|---|---|---|
Eloquent, save() with 1,000 models loaded | 1.5 ms | 1 |
Doctrine, flush() with 1,000 managed entities | 9.7 ms | 3 |
Doctrine, flush() with one managed entity | 0.8 ms | 3 |
With the default change tracking policy, Doctrine checks its managed entities on flush(). With 1,000 entities, the measured operation took about 12 times as long as it did with one entity. The counter recorded three operations in both cases. Eloquent's save() saves the individual model. If a Doctrine worker processes many entities in one EntityManager, keep an eye on the size of its unit of work between batches.
In the insert test, each variant wrote 1,000 rows in a transaction that I rolled back.
| Variant | Time | Operations counted |
|---|---|---|
Eloquent, create() in a loop | 725.6 ms | 1,000 |
Doctrine, persist() and flush() in batches of 100 | 416.5 ms | 1,020 |
Eloquent, one insert() call | 30.3 ms | 1 |
Doctrine reuses prepared statements for entity inserts. The insert() variant sends one SQL statement and bypasses model creation and model events. It fits jobs that only need to insert the rows.
I also checked Eloquent's regular save(). Changing one field resulted in an update to that field and updated_at. Assigning the field its existing value yielded no UPDATE. With $touches set, loading and saving a post took four queries instead of two. Eloquent also loaded the relationship and updated the parent's timestamp.
An exception before the third write
In the final check, I prepared two related records and threw an exception before the third. The harness checked which rows the same connection could see, then rolled back the outer test transaction.
| Rows visible before rollback | Eloquent after two create() calls | Doctrine after two persist() calls, before flush() |
|---|---|---|
| Users | 1 | 0 |
| Posts | 1 | 0 |
-
create()the user Executes anINSERTfor the user. -
create()the post Executes anINSERTfor the post. - Exception before the third write One user and one post are visible.
-
persist()the user Schedules an insert for the user. -
persist()the post Schedules an insert for the post. -
Exception before
flush()No new rows are visible.
Each create() inserted a row immediately. Doctrine scheduled both inserts, and execution stopped before flush(). To make several writes atomic in Laravel, put them in DB::transaction() and let the exception propagate out of the callback. Doctrine wraps the writes of a single flush() in a transaction. This test checked the state before flush().
What to check in your application
For a list page, I would start with the shape of the result and how it loads relationships. For a worker, I would record the size of the unit of work and measure how long flush() takes near the end of a batch. If a bulk UPDATE can run between reads, add a test for what a second call to find() returns.