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
OSX: Add internal cache for UI system fonts as well #2497
Conversation
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! This should definitely help, but if it matters, it could be improved further.
I also think we could use just a std::vector<wxCFRef<CTFontRef>>
(or even a std::array
if we wanted the really optimal solution) instead of a map
because CTFontUIFontType
is just a small integer which practically begs to be used as an index into the vector.
|
||
wxCFRef<CTFontRef> ctfont; | ||
|
||
auto item = s_UIFontCache.find(uifont); |
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.
I don't know if we care about efficiency that much here, but using find()
followed by emplace()
does the search in the map twice and the typical thing to do to avoid it is to use lower_bound()
to get the iterator either for the object that we want or for insertion later.
However this might be irrelevant because of my more global comment about using a vector instead.
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 suggestion, yes, I'm not really fluent on these unfortunately ...
SetFont(ctfont); | ||
m_info.InitFromFont(ctfont); |
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.
This still involves calling CTFontCopyGraphicsFont()
and doing everything wxNativeFontInfo::InitFromFontDescriptor()
does, even for the cached fonts. I haven't done any profiling, so perhaps all this is "free" compared to CTFontCreateUIFontForLanguage()
itself, but perhaps we should cache the entire wxFont
objects to avoid doing all this every time?
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.
Yes, that's why I wrote Andy in the Trac report, to please test things, because if this is expensive, then indeed my first idea of caching wxFontRefData
would be unavoidable
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.
I think that if there is any doubt, we should go with caching wxFont[RefData]
and use a wxModule
to clean it up on GUI shutdown, it's slightly more code, but really not difficult. I can do it, if you'd like?
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.
I think that if there is any doubt, we should go with caching
wxFont[RefData]
and use awxModule
to clean it up on GUI shutdown, it's slightly more code, but really not difficult. I can do it, if you'd like?
that would be great, thank you, actually I'd cache the wxFontDataRefs in the wxFont::wxFont(wxOSXSystemFont font)
, not only the ones used in settings.mm
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.
OK, I'll do it. I'd still be grateful for any testing, however.
Co-authored-by: VZ <vz-github@zeitlins.org>
you're right, thank you, I didn't look at the value range of this type. |
Closing in favour of #2499. |
see #19191