Skip to content

Speed up archive unpacking performance#36

Merged
Hackwar merged 2 commits intojoomla-framework:3.x-devfrom
dryabov:patch-2
Jan 21, 2024
Merged

Speed up archive unpacking performance#36
Hackwar merged 2 commits intojoomla-framework:3.x-devfrom
dryabov:patch-2

Conversation

@dryabov
Copy link
Copy Markdown
Contributor

@dryabov dryabov commented Jan 15, 2024

Summary of Changes

Speed up archive unpacking performance by using offset argument in unpack (instead of substr).

Testing Instructions

Run phpunit to check if all tests have passed.

Documentation Changes Required

None.

@dryabov dryabov changed the title Speed up archive unpacking performance (v2) Speed up archive unpacking performance Jan 15, 2024
@Hackwar
Copy link
Copy Markdown
Contributor

Hackwar commented Jan 16, 2024

Thank you for your PR. Performance improvements like these are very welcome. Looking at the code on a first glance however, I'm not entirely sure if this would still produce the correct results. I only looked at the gzip code so far and to me it looks as if the substr() calls in line 174 and 190 are actually necessary, otherwise it would read to much data, right? I'll have another look into this soon.

@dryabov
Copy link
Copy Markdown
Contributor Author

dryabov commented Jan 21, 2024

I've done a performance test by extracting the Joomla 5.0.2 tar.gz package using the following simple script (and extracting to tmpfs):

use Joomla\Archive\Archive;
ini_set('memory_limit', '256M'); // PHP's default 128M limit is not sufficient to store unzipped tar
require __DIR__ . '/vendor/autoload.php';
(new Archive())->extract($argv[1], $argv[2]);

The results are below:

Extract tgz (patched archive)

real    0m1.087s
user    0m0.587s
sys     0m0.498s

Extract tgz (old archive)

real    2m52.085s
user    1m34.213s
sys     1m17.455s

Fantastic 158x speedup!

PS. I've run the patched version before the original to avoid replies like "your patched version uses a warmed file cache".

PPS. This test was run on PHP 8.1 with the -n CLI argument to use default config.

@Hackwar Hackwar merged commit 8dd5190 into joomla-framework:3.x-dev Jan 21, 2024
@Hackwar
Copy link
Copy Markdown
Contributor

Hackwar commented Jan 21, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants