Summary: | perf: GetDefaultScriptType | ||
---|---|---|---|
Product: | LibreOffice | Reporter: | Michael Meeks <michael.meeks> |
Component: | Calc | Assignee: | Not Assigned <libreoffice-bugs> |
Status: | NEW --- | ||
Severity: | normal | CC: | aron.budea, caolan.mcnamara, erack, jluth, noelgrandin |
Priority: | medium | Keywords: | perf |
Version: | 24.2.0.0 beta1+ | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: | |||
Crash report or crash signature: | Regression By: | ||
Attachments: | a profile mostly of the end of loading |
Description
Michael Meeks
2024-03-15 12:56:55 UTC
That doesn't look like pointer-chasing but in MsLangId::getScriptType() the chains of nLang.anyOf(...) and primary(nLang).anyOf(...) (that previously before using o3tl::strong_int()::anyOf() were nested switch/case constructs). My suggestion: Take a shortcut to handle a few well-known often occurring Western languages/locales beforehand, like if (nLang == LANGUAGE_ENGLISH_US || primary(nLang).anyOf( primary(LANGUAGE_ENGLISH_US), primary(LANGUAGE_SPANISH_MODERN), primary(LANGUAGE_FRENCH), primary(LANGUAGE_GERMAN))) return css::i18n::ScriptType::LATIN; Switch sounds good to me =) Somewhere in the profile I saw a red-black tree in use and I suspect RB trees are a pointer-chasing performance hazard on real modern hardware; but perhaps I mis-read this one. Would it not be better to cache the answer? have a single entry 'nLang -> ScriptType' static cache in that function ? I assume that 99.99% of the time this is the same language ? =) mmeeks, this was defintely a profile of an optimised build right? I just find it hard to believe that the compiler did not inline the anyOf method into a comparison chain. If it is an optimised build, I possibly need to attribute anyOf() with __always_inline__ Hmmm, my optimised build does not show any of that, possibly master has improved somewhat, and that is a different branch? Ah! so - of course, it is quite possible that (as you say) this is not optimized; and so - a total waste of time; seems so - my bad - sorry! Still - this is a lookup we do repeatedly of one fixed lang against some complex machinery so a one item cache might be useful (?) =) or just have both the nLang and the ScriptType set in the global state when they are mutated on set ? =) |