Opened 4 years ago
Closed 3 years ago
#10779 closed enhancement (fixed)
optimised unzip_file()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.0 |
| Component: | Filesystem | Version: | 2.9 |
| Severity: | normal | Keywords: | needs-testing featured |
| Cc: | Denis-de-Bernardy |
Description (last modified by dd32)
Patch contains
- Optimised unzip_file() function
- Reduced the number of IO operations required (mainly is_dir())
- Simplifies logic to make reading easier.
---
Also note, I played with extracting a file at a time from the ZIP, and writing to the filesystem directly, While it decreased the memory usage from ~12MB to 3MB for the entire unzip operation, It increased the operation time from 5s to 70s, So i've left it to consume memory in order to speed things up.
Attachments (2)
Change History (18)
It might be too late now to put the unzip_file() changes into 2.9. Can we separate out the phpdoc changes?
- Description modified (diff)
- Keywords needs-testing added
- Milestone changed from 2.9 to 3.0
- Summary changed from file.php: PHPDoc + optimised unzip_file() to optimised unzip_file()
The phpdoc has gone in with another ticket, I forgot i had submitted it here already.
- Status changed from new to accepted
I'm going to refresh this patch, and do furthur testing of the changes in the near future.
- Cc Denis-de-Bernardy added
...What?
Yes, The updated patch will be resubmitted once i retest its working with the latest changes to the codebase.
Just did some benchmarks on the code.
First item is an array of the number of times each function is called. Then a total of the calls:
Before:
array(6) {
["connect"]=>
int(1)
["mkdir"]=>
int(83)
["put_contents"]=>
int(753)
["exists"]=>
int(836)
["chmod"]=>
int(836)
["is_dir"]=>
int(1754)
}
Total: 4263
After:
array(6) {
["connect"]=>
int(1)
["is_dir"]=>
int(3)
["mkdir"]=>
int(83)
["put_contents"]=>
int(753)
["exists"]=>
int(836)
["chmod"]=>
int(836)
}
Total: 2512
is_dir() is expensive on FTP systems, and all of those exists() calls can be removed by letting chmod() either suceed, or fail. instead of checking if it'll fail (if it exists) and then letting it either suceed or fail.
comment:10
dd32 — 3 years ago
Oh, that was extracting the WordPress 2.9.1 archive on a system using the Direct method..
comment:11
dd32 — 3 years ago
comment:12
dd32 — 3 years ago
- Keywords needs-testing added; needs-patch removed
Commited this for now, Will see how it fares for others.
For those wanting to test it, just run a few Plugin installs and upgrades and see how you go.
- Keywords bug-hunt added
comment:14
dd32 — 3 years ago
See #11979, Broke it for one person, with one particular archive.. Havnt yet been able to reproduce it
- Keywords featured added; bug-hunt removed
comment:16
dd32 — 3 years ago
- Resolution set to fixed
- Status changed from accepted to closed
Closing as fixed. Open new tickets for any issues encountered.

s/for/foreach on a loop for readability