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

Memoize fontkit.fk_shape #155

Merged
merged 3 commits into from
Dec 27, 2018

Conversation

akinsho
Copy link
Member

@akinsho akinsho commented Dec 26, 2018

fixes #115, memoizes the fn in a similar way as the getTexture function

@@ -39,8 +39,11 @@ type dimensions = {
height: int,
};

let _memoizedFontShape = Memoize.make(Fontkit.fk_shape);
Copy link
Member

@bryphe bryphe Dec 26, 2018

Choose a reason for hiding this comment

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

There's one gotcha with our built-in memoization - it only supports single argument functions.

This means, with the current implementation, we'd actually only be memoizing the 'font' parameter. To speed up this code-path, we'll need to cache the tuple of (font, text).

So I think we'd need to update our memoize function to take in a pair of (font, text) - that's why we have the somewhat awkward syntax in our other memoized functions:

let _getTexture = ((font: Fontkit.fk_face, codepoint: int)) => {

let _getTexture = ((font: Fontkit.fk_face, codepoint: int)) => {
...
}


let _memoizedGetTexture = Memoize.make(_getTexture);
let getTexture = (font: Fontkit.fk_face, codepoint: int) =>
  _memoizedGetTexture((font, codepoint));

Note the extra ( and ) in the _getTexture and the way we call _memoizedGetTexture. The _getTexture is actually taking a single argument of (font, codepoint), and the getTexture is converting its arguments to a tuple to send them into _memoizedGetTexture.

Let me know if you have any questions!

Copy link
Member

@bryphe bryphe left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @Akin909 ! Left a comment around the memoization strategy - I think we'll need a tweak to get the full benefit of memoization in this scenario.

Copy link
Member

@bryphe bryphe left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for fixing this, @Akin909 🎉

@akinsho akinsho merged commit d665fdc into revery-ui:master Dec 27, 2018
@akinsho akinsho deleted the feature/memoize-fontkit-shape branch December 27, 2018 20:36
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.

Performance: Cache results of hb_shape calls
2 participants