Comments (4)
Thanks for the report @TavoNiievez. You are correct and I did some tests but didn't see any significant memory savings by adding a ->clear()
. Do you see something different?
Further, calling ->clear()
creates problems with relationships:
PostFactory::new()->create([
'category' => CategoryFactory::new(),
]);
In this example, the Category is persisted and the em
is flushed and cleared (removing it from memory). When the Post is persisted, the flush gives "A new entity was found through the relationship 'App\Entity\Post#category' that was not configured to cascade persist operations for entity..." exception (because the Category is no longer managed by the em
). Hope that makes sense...
I would like to eventually have only 1 flush per ->create()
/->createMany()
- probably for a 2.0 unless I can figure out a way to implement without a BC break.
from foundry.
Ok, it's just that I remember that in a legacy application that I managed, the database saved the json data of the users' invoices, at some point we changed this logic:
public function load(ObjectManager $manager): void {
for ($i = 0; $i < 800; $i++) {
$invoice = new Invoice();
$invoice->setJsonData('C:/..');
//...
$manager->persist($invoice);
}
$manager->flush();
}
for this other one:
public function load(ObjectManager $manager): void {
for ($i = 0; $i < 800; $i++) {
$invoice = new Invoice();
$invoice->setJsonData('C:/..');
//...
$manager->persist($invoice);
+ $manager->flush();
+ $manager->clear();
}
- $manager->flush();
}
and we noticed a difference of 4 seconds... and since the tests had to be executed dozens of times in a day it was an improvement. I was migrating to Foundry in a more updated application under Symfony 5 when I remembered that scenario and decided to ask, but if you performed the tests and did not notice significant differences I guess that solves my doubt.
from foundry.
Thanks @TavoNiievez - I'll keep this in mind. If you do see any performance issues yourself, let me know!
from foundry.
I will inform you, thanks to you ;)
from foundry.
Related Issues (20)
- `make:factory` fails when there is more than one level of embedded classes HOT 2
- Named `FactoryCollection` constructors don't have proper type declarations HOT 4
- Performance Problem with random HOT 4
- Doctrine embeddables with v2 HOT 8
- [Tests] use 2 schemas in the same database
- Migration Guide to version 2 HOT 3
- V2 and phpstan HOT 5
- Upgrade from 1.37 to 1.38 introduce a memory leak HOT 16
- H
- [2.x] ArgumentCountError thrown when passing $attributes array to closure in event HOT 9
- Creation of dynamic property App\Entity\MyEntity::$_autoRefresh is deprecated HOT 6
- Issue with Proxy Entities in Version 2 HOT 14
- Zenstruck\Foundry\Factory::$class must not be accessed before initialization HOT 6
- Find functions do not refresh entity HOT 2
- Attribute wrapped in a Foundry Proxy is not compatible with `Symfony\Component\VarExporter\LazyProxyTrait` HOT 6
- Foundry should not remove symfony-s errorHandlers HOT 6
- Global state relationships and flush_after HOT 13
- How to fix deprecation notices HOT 9
- [2.0] Problem with inversed `OneToOne` relationships HOT 4
- [2.0] No autocompletion for Proxy objects HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foundry.