llaville / php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions
https://llaville.github.io/php-compatinfo-db/6.12/
BSD 3-Clause "New" or "Revised" License
10 stars 3 forks source link

Reduce size of PHAR version #138

Closed llaville closed 9 months ago

llaville commented 9 months ago

New Feature request

Summary

Reduce size of PHAR version built with BOX project

Description

When your project have files and/or directories not auto-discoverable by BOX, there are two strategies:

First one is to identify all files and/or directories on the box.json config file with :

WARNING In such context, the Auto-discover feature is disabled ( see on BOX output : ? Auto-discover files? No)

Second one, use always the Auto-discover feature of BOX and add only files and/or directories that BOX cannot detected.

llaville commented 9 months ago

Actually, with master branch (commit 782be5c749b935bc114a225a1ca40b9725e2c6e3), and such box.json config file

{
    "alias": "compatinfo-db.phar",
    "directories": ["bin", "config", "data", "src", "vendor"],
    "compression": "GZ"
}

Auto-discover BOX feature is disabled (due to directories usage) : see BOX compile ouput => ? Auto-discover files? No

And we can look on compile output these two lines :

? Adding files
    > 4368 file(s)
 // PHAR: 4401 files (3.59MB)

Now, we will follow a better strategy, by keeping the Auto-discover BOX feature enabled and specify only the directories that cannot be found by BOX

{
    "alias": "compatinfo-db.phar",
    "force-autodiscovery": true,
    "directories": ["config", "data"],
    "compression": "GZ"
}

And we can look on compile output these two lines :

? Adding files
    > 3464 file(s)
 // PHAR: 3507 files (2.60MB)

Files removed are from vendor(s) : unecessary like composer.*, Markdown files

To check difference, we can extract contents of PHAR versions built into tempory folders

llaville commented 9 months ago

@theofidry WDYT about my analysis to improve PHAR size ?

theofidry commented 9 months ago

👍

If you want to push things further leveraging the finders is the way to go but I highly doubt it is worth the extra efforts, especially since your final artifact is already quite small (<3MB).

A few other ways to optimize:

Those are general recommendations, but again <3MB is already quite small for a PHAR IMO.

llaville commented 9 months ago

@theofidry Thanks for your feedback. But I wanted here to show gain (1 Mb) between the two strategies I've explained !