Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better performance for reading dimensions of SVG images #23

Merged
merged 6 commits into from
Nov 20, 2016

Conversation

ausi
Copy link
Member

@ausi ausi commented Nov 16, 2016

With this PR Image::getDimensions() reads SVG files only partially to save IO, parsing time and memory. And it doesn’t call getimagesize() on SVG images anymore.

Todo:

  • Check if the wrapper compress.zlib:// is supported on all platforms
  • Write tests

@ausi
Copy link
Member Author

ausi commented Nov 16, 2016

A quick performance test looks promising:

Size (Bytes) images/sec before images/sec now
100 7,699 7,518
1,000 7,345 7,532
10,000 5,841 7,557
100,000 1,888 7,573
1,000,000 216 7,583

In comparison reading the size of a jpg/png/gif reaches about 23,500 images/sec.

@leofeyer
Copy link
Member

Check if the wrapper compress.zlib:// is supported on all platforms

I think it is: http://php.net/manual/de/ref.zlib.php#37482

@ausi
Copy link
Member Author

ausi commented Nov 17, 2016

If we want to be sure we could add an in_array('compress.zlib', stream_get_wrappers()) check.

@leofeyer
Copy link
Member

Maybe in the Contao check or Contao manager but rather not in the core. On a page with 100 images, the check would be executed 100 times otherwise.

@@ -176,15 +176,27 @@ public function setImportantPart(ImportantPartInterface $importantPart = null)
*/
private function getSvgSize()
{
static $zlibSupport;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a static class property such as self::$zlibSupport?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think so, because it is only used in this method and nowhere else.
The exception would be if our styleguide doesn’t allow static function variables at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, our style guide does not forbid to use them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I keep it as is then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if you prefer. 😄

@ausi ausi changed the base branch from master to hotfix/0.3.1 November 20, 2016 13:22
@ausi ausi merged commit b259e28 into hotfix/0.3.1 Nov 20, 2016
@ausi ausi deleted the fix/svg-image-size-performance branch November 20, 2016 13:27
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