From f5f3d36ec71cfbe765016db85e695184e0c43fe8 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Wed, 12 Jun 2024 18:31:58 +0200 Subject: [PATCH] [TASK] Reduce memory usage of a greedy unit test > Build/Scripts/runTests.sh Before: Memory: 469.06 MB After: Memory: 373.02 MB Reason: phpunit executes data providers early and keeps data sets in memory. The "xml parser big content" tests create megabytes of data kept in memory. Moving the data generation from data providers to the test execution reduces overall memory usage significantly. Resolves: #104076 Releases: main, 12.4, 11.5 Change-Id: I0ad49824fc1d4c309158b74474853d36af22ffb5 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84670 Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Unit/Serializer/Typo3XmlParserTest.php | 50 +++++-------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php b/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php index b227c03916e4..81c0b556b786 100644 --- a/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php +++ b/typo3/sysext/core/Tests/Unit/Serializer/Typo3XmlParserTest.php @@ -357,45 +357,12 @@ class Typo3XmlParserTest extends UnitTestCase ); } - /** - * @return array[] - */ public static function decodeHandlesBigXmlContentDataProvider(): array { return [ - '1mb' => [ - '<?xml version="1.0" encoding="utf-8" standalone="yes"?> - <T3FlexForms> - <data> - <field index="settings.persistenceIdentifier"> - <value index="vDEF">' . str_repeat('1', 1024 * 1024) . '</value> - </field> - </data> - </T3FlexForms>', - str_repeat('1', 1024 * 1024), - ], - '5mb' => [ - '<?xml version="1.0" encoding="utf-8" standalone="yes"?> - <T3FlexForms> - <data> - <field index="settings.persistenceIdentifier"> - <value index="vDEF">' . str_repeat('1', 5 * 1024 * 1024) . '</value> - </field> - </data> - </T3FlexForms>', - str_repeat('1', 5 * 1024 * 1024), - ], - '10mb' => [ - '<?xml version="1.0" encoding="utf-8" standalone="yes"?> - <T3FlexForms> - <data> - <field index="settings.persistenceIdentifier"> - <value index="vDEF">' . str_repeat('1', 10 * 1024 * 1024) . '</value> - </field> - </data> - </T3FlexForms>', - str_repeat('1', 10 * 1024 * 1024), - ], + '1mb' => [1], + '5mb' => [5], + '10mb' => [10], ]; } @@ -403,8 +370,17 @@ class Typo3XmlParserTest extends UnitTestCase * @test * @dataProvider decodeHandlesBigXmlContentDataProvider */ - public function decodeHandlesBigXmlContent(string $input, string $testValue): void + public function decodeHandlesBigXmlContent(int $megabytes): void { + $input = '<?xml version="1.0" encoding="utf-8" standalone="yes"?> + <T3FlexForms> + <data> + <field index="settings.persistenceIdentifier"> + <value index="vDEF">' . str_repeat('1', $megabytes * 1024 * 1024) . '</value> + </field> + </data> + </T3FlexForms>'; + $testValue = str_repeat('1', $megabytes * 1024 * 1024); $xmlDecoder = new Typo3XmlParser(); $expected = [ 'data' => [ -- GitLab