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

Convert Font Cache from PHP to JSON Files #935

Merged
merged 1 commit into from Dec 11, 2018

Conversation

Projects
None yet
2 participants
@jakejackson1
Copy link
Contributor

jakejackson1 commented Dec 11, 2018

This PR standardised the font cache. Instead of crudely generating PHP files with font data, it stores the information in JSON files.

JSON cache files has a number of benefits:

  1. The code to generate the files is much smaller.
  2. The data doesn't need to be escaped
  3. It is easier to test and modify
  4. More compatible on shared hosting with security that limit the dynamic creation of PHP files

Backwards Compatibility
This is fully backwards compatible. There is a one-time font cache refresh to generate the new JSON files, then it's business as usual. The font cache doesn't need flushing before hand.

I tested this PR against the Mpdf Example folder and found no visual regressions.

Benchmarks
By forgoing the PHP cache, we lose OPCaching on these files, but I've kept the JSON cache performant none-the-less and there's little change in performance.

Average (5 runs) for all Mpdf Example Templates using the CLI:

  • PHP Cache: 147.839
  • JSON Cache: 148.221

Difference: 0.26%

Average (5 runs) for Example 61 in the browser with OPCache Enabled:

  • PHP Cache: 21.036661
  • JSON Cache: 21.271170

Difference: 1.11%

Bugs
A few PHP notices were fixed during this revision. See src/TTFontFile.php and utils/font_dump.php. Note: I noticed all the other scripts in utils no longer work and need to be refined (or removed).

@jakejackson1 jakejackson1 force-pushed the GravityPDF:font-files branch from b4fdb30 to b04fcaa Dec 11, 2018

@jakejackson1 jakejackson1 force-pushed the GravityPDF:font-files branch from b04fcaa to 6c61a8d Dec 11, 2018

@jakejackson1 jakejackson1 changed the title Convert Font Cache from PHP Templates to JSON Convert Font Cache from PHP to JSON Files Dec 11, 2018

@finwe finwe merged commit 93515f7 into mpdf:development Dec 11, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@finwe

This comment has been minimized.

Copy link
Member

finwe commented Dec 11, 2018

Awesome. Thanks a lot.

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