-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Memoize fontkit.fk_shape #155
Conversation
src/UI/FontRenderer.re
Outdated
@@ -39,8 +39,11 @@ type dimensions = { | |||
height: int, | |||
}; | |||
|
|||
let _memoizedFontShape = Memoize.make(Fontkit.fk_shape); |
There was a problem hiding this comment.
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:
Line 14 in 7b8ccf7
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!
There was a problem hiding this 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.
There was a problem hiding this 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 🎉
fixes #115, memoizes the fn in a similar way as the
getTexture
function