Conversation
createMany() materializes every factory and every object upfront, so memory grows linearly with the count and creating a large amount of them is impossible. bulkCreate() trades the return value for constant memory: factories are yielded one at a time, and each batch is flushed then detached from the object manager.
nikophil
commented
Sep 22, 2026
| throw new \LogicException('bulkCreate() can only be used with a factory which persists its objects.'); | ||
| } | ||
|
|
||
| Configuration::instance()->persistence()->flushInBatches( |
Member
Author
There was a problem hiding this comment.
I'm very reluctant to couple FactoryCollection and PersistenceManager, this is one of my main problems with this PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #883.
Creating a large amount of objects is impossible today:
createMany()materializes every factory and every object upfront, so memory grows linearly with the count — 20k objects already peak at 256MB.bulkCreate()trades the return value for constant memory: factories are yielded one at a time, and each batch is flushed then detached from the object manager.Measured on 1M entities: flat memory from start to finish (+5MB overall, 76MB peak, 478s). The same run with
createMany()needs several GB and never completes.It deliberately reimplements nothing. Hooks, events, relations and identifiers behave exactly as with
create(), which is why the diff stays this small and why it works for both ORM and ODM.Draft — not verified yet: ODM, generated proxies, and a run without dama/doctrine-test-bundle (ie. with a real commit per batch). The method name is also open for discussion.
@seb-jean could you try the PR?