25. Improving Performance

25.1. Bytecode Cache

It is highly recommended to make use of a bytecode cache like OPcache. A bytecode cache removes the need for parsing PHP code on every request and can greatly improve performance.

OPcache などのバイトコード キャッシュを使用することを強くお勧めします。バイトコード キャッシュを使用すると、リクエストごとに PHP コードを解析する必要がなくなり、パフォーマンスが大幅に向上します。

“If you care about performance and don’t use a bytecode cache then you don’t really care about performance. Please get one and start using it.”

「パフォーマンスに関心があり、バイトコードキャッシュを使用しない場合、パフォーマンスはあまり気にしません。入手して使い始めてください。」

Stas Malyshev, Core Contributor to PHP and Zend Employee

Stas Malyshev、PHP および Zend Employee へのコア貢献者

25.2. Metadata and Query caches

As already mentioned earlier in the chapter about configuring Doctrine, it is strongly discouraged to use Doctrine without a Metadata and Query cache.

Doctrine の設定に関する章ですでに述べたように、メタデータとクエリのキャッシュなしで Doctrine を使用することは強く推奨されません。

Operating Doctrine without these caches means Doctrine will need to load your mapping information on every single request and has to parse each DQL query on every single request. This is a waste of resources.

これらのキャッシュなしで Doctrine を操作すると、Doctrine はすべてのリクエストでマッピング情報をロードする必要があり、すべてのリクエストで各 DQL クエリを解析する必要があります。これはリソースの無駄です。

The preferred cache adapter for metadata and query caches is a PHP file cache like Symfony’s PHP files adapter. This kind of cache serializes cache items and writes them to a file. This allows for opcode caching to be used and provides high performance in most scenarios.

メタデータおよびクエリ キャッシュに推奨されるキャッシュ アダプターは、Symfony の PHP ファイル アダプターのような PHP ファイルキャッシュです。この種類のキャッシュは、キャッシュ アイテムをシリアル化し、ファイルに書き込みます。これにより、オペコード キャッシングを使用できるようになり、ほとんどのシナリオで高いパフォーマンスが得られます。

See Types of Caches

キャッシュの種類を参照してください

25.3. Alternative Query Result Formats

Make effective use of the available alternative query result formats like nested array graphs or pure scalar results, especially in scenarios where data is loaded for read-only purposes.

特に読み取り専用の目的でデータが読み込まれるシナリオでは、ネストされた配列グラフや純粋なスカラー結果など、利用可能な代替クエリ結果形式を効果的に使用します。

25.4. Read-Only Entities

You can mark entities as read only (See metadata mapping references for details).

エンティティを読み取り専用としてマークできます (詳細については、メタデータ マッピングのリファレンスを参照してください)。

This means that the entity marked as read only is never considered for updates. During flush on the EntityManager these entities are skipped even if properties changed.

これは、読み取り専用としてマークされたエンティティが更新対象と見なされないことを意味します。EntityManager でのフラッシュ中に、プロパティが変更された場合でも、これらのエンティティはスキップされます。

Read-Only allows to persist new entities of a kind and remove existing ones, they are just not considered for updates.

読み取り専用では、種類の新しいエンティティを永続化し、既存のエンティティを削除できます。それらは更新の対象とは見なされません。

See @Entity

@エンティティを参照

You can also explicitly mark individual entities read only directly on the UnitOfWork via a call to markReadOnly():

また、markReadOnly() への呼び出しを介して、theUnitOfWork で直接、個々のエンティティを読み取り専用として明示的にマークすることもできます。

$user = $entityManager->find(User::class, $id);
$entityManager->getUnitOfWork()->markReadOnly($user);

Or you can set all objects that are the result of a query hydration to be marked as read only with the following query hint:

または、次のクエリ ヒントを使用して、クエリ ハイドレーションの結果であるすべてのオブジェクトを読み取り専用としてマークするように設定できます。

$query = $entityManager->createQuery('SELECT u FROM App\\Entity\\User u');
$query->setHint(Query::HINT_READ_ONLY, true);

$users = $query->getResult();

25.5. Extra-Lazy Collections

If entities hold references to large collections you will get performance and memory problems initializing them. To solve this issue you can use the EXTRA_LAZY fetch-mode feature for collections. See the tutorial for more information on how this fetch mode works.

エンティティが大規模なコレクションへの参照を保持している場合、それらを初期化する際にパフォーマンスとメモリの問題が発生します。この問題を解決するには、コレクションに EXTRA_LAZY フェッチ モード機能を使用できます。このフェッチ モードの仕組みの詳細については、チュートリアルを参照してください。

25.6. Temporarily change fetch mode in DQL

See Temporarily change fetch mode in DQL

DQL でフェッチ モードを一時的に変更するを参照してください。

25.7. Apply Best Practices

A lot of the points mentioned in the Best Practices chapter will also positively affect the performance of Doctrine.

ベスト プラクティスの章で言及されている多くのポイントは、Doctrine のパフォーマンスにも良い影響を与えます。

See Best Practices

ベスト プラクティスを見る

25.8. Change Tracking policies

See: Change Tracking Policies

参照: 追跡ポリシーの変更

Table Of Contents

Previous topic

24. Caching

24. キャッシング

Next topic

26. Tools

26. ツール

This Page

Fork me on GitHub