Page 1 of 1

Xaml string parsing times at load

Posted: 21 Oct 2024, 18:17
by groth
Hi all,

We've noticed there's quite a bit of processing time devoted to string parsing when loading up Xaml files at startup. Are there plans to support a binary format for xaml to eliminate some of these issues? I'd like to be able to pre-process my xaml files into binary files to improve load and processing time when starting up.

Microsoft has support for binary xaml (baml) that does something similar.

Thanks!

Re: Xaml string parsing times at load

Posted: 21 Oct 2024, 18:41
by jsantos
Yes, there are plans for this.

Could you please go to UI.cpp and make sure NS_XAML_RELOAD_ENABLED is defined to get timing information about parsing and instancing.
  #if NS_XAML_RELOAD_ENABLED
    uint64_t t0 = HighResTimer::Ticks();
    Ptr<XamlParser> parser = MakePtr<XamlParser>(uri, true);
    parser->Parse(stream);

    uint64_t t1 = HighResTimer::Ticks();
    NS_LOG_TRACE("(=) Parsing %s (%.0f ms)", uri.Str(), 1000.0 * HighResTimer::Seconds(t1 - t0));

    tree = XamlReader::Load(parser, root, uri);
    uint64_t t2 = HighResTimer::Ticks();
    NS_LOG_TRACE("(=) Instancing %s (%.0f ms)", uri.Str(), 1000.0 * HighResTimer::Seconds(t2 - t1));
In our internal tests, parsing is around 15%.

Re: Xaml string parsing times at load

Posted: 22 Oct 2024, 17:38
by groth
Hi!
Using those tests, it looks like I'm getting the following totals going from startup to the UI fully loaded.

Total string parsing = 63.818ms
Total Instancing = 216.920ms
About 23% of total parse time spent string parsing.

Max single document string parsing = 4.547ms
Max single document instancing = 71.631ms (primary theme xaml)

I expect these numbers only to get worse as we continue on through development and the UI becomes more complicated. So, being able to eliminate 4+ frames out of the startup by using a binary representation of the xaml is an easy win, so definitely looking forward to when that implementation is available.

Re: Xaml string parsing times at load

Posted: 29 Oct 2024, 17:10
by jsantos
I expect these numbers only to get worse as we continue on through development and the UI becomes more complicated. So, being able to eliminate 4+ frames out of the startup by using a binary representation of the xaml is an easy win, so definitely looking forward to when that implementation is available.
Just one more question: is this issue occurring with XAML files that are instantiated multiple times (such as UserControls), or only with single-use XAMLs? We’re also considering adding support for faster instantiation of UserControls by storing the node tree in memory to avoid repeated parsing.