GithubHelp home page GithubHelp logo

Comments (4)

kbond avatar kbond commented on September 28, 2024

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.

 avatar commented on September 28, 2024

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.

kbond avatar kbond commented on September 28, 2024

Thanks @TavoNiievez - I'll keep this in mind. If you do see any performance issues yourself, let me know!

from foundry.

 avatar commented on September 28, 2024

I will inform you, thanks to you ;)

from foundry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.