-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 Use
probe-image-size
to speed up fetching image dimensions
no issue Fetching images across the network to get their dimensions is really slow. In the previous implementation we were fetching the entire image before using it to determine the image dimensions. However, for most images we don't need all of the data! Image dimensions can usually be determined from the headers or other information that is stored near the beginning of an image file, we should take advantage of that to massively speed up our dimension calculations and save a lot of network bandwidth. - use `probe-image-size` to fetch only enough of an image that is needed to get the dimensions - fall back to `image-size` for formats which `probe-image-size` doesn't support - replace `got` with `request` so we're not including two different request libraries - use `request-promise` wrapper library to simplify the code (uses `bluebird` under the hood which is the same as the `async` library that we're using As an example of the speedup offered, here are my tests which were using this library inside Ghost. The test page had 10 reasonably sized external images and the reported time is the initial amperization before caching. ``` image-size only: INFO amp.parse http://ghost.blog/2019/06/08/test/ 52278ms INFO amp.parse http://ghost.blog/2019/06/08/test/ 52717ms INFO amp.parse http://ghost.blog/2019/06/08/test/ 50582ms average: 51,859ms probe-image-size w/ image-size fallback: INFO amp.parse http://ghost.blog/2019/06/08/test/ 11147ms INFO amp.parse http://ghost.blog/2019/06/08/test/ 12297ms INFO amp.parse http://ghost.blog/2019/06/08/test/ 11188ms average: 11,544ms ``` Result: ~4.5x faster
- Loading branch information
1 parent
99064b8
commit c9879b1
Showing
4 changed files
with
170 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.