Alex141 / CalcBinding

Advanced WPF Binding which supports expressions in Path property and other features

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

slow startup

jtorjo opened this issue · comments

Hi Alex,

First off, insanely awesome lib! Been using it for more than a year now!
Having said that, when there's a LOT of databinding initializations, the startup is really slow.
I basically have a list of databound controls. For 240 controls, it takes roughly 10-12 seconds to startup.

Imagine this code:

foreach (var beat in model.music_beats) {
    var ctrl = new music_beat_ctrl { DataContext = beat, Height = ActualHeight};
    canvas.Children.Add(ctrl);
}

Each music_beat_ctrl is databound, more or less:

<materialDesign:PackIcon Kind="Link" RenderTransformOrigin="0.5,0.5" Width="18" Height="18" Margin="-9 0 0 0"
Visibility="{c:Binding 'linked or highlighted'}"
Foreground="{c:Binding 'highlighted ? media:Brushes.LightSeaGreen : media:Brushes.DimGray'}"
/>

<materialDesign:PackIcon Kind="GuitarElectric" Foreground="DimGray"
Width="{c:Binding 'type == local:beat_type.major ? 18 : 12'}"
Height="{c:Binding 'type == local:beat_type.major ? 18 : 12'}"
Opacity="{c:Binding 'type == local:beat_type.major ? 1 : 0.3'}"
ToolTip="{c:Binding 'type == local:beat_type.major ? 'Major Beat' : 'Minor Beat''}"
/>

While doing profiling, it seems to end up calling DynamicExpresso.Interpretor.constructor 960 times, which ends up with 28800 calls to DynamicExpresso.Interpretor.Reference - I would assume these should be able to be cached somehow?

Hi jtorjo,

Thank you :) Yes, I think its really needed to add some cache for parsed expressions. I thought about expressions cache when testing grid scenarios, but is was ok due to wpf optimizations for binding expressions.

I'm preparing edits for that task. If you want, you can provide a minimal example (full xaml + cs) close to your real code, so I can make sure that the performance is better in that case

Awesome, will have that done over the weekend at the latest

ok, will wait

It will take a bit for me to create a simple standalone xaml + cs - that's why I said "over the weekend". Hopefully it will be sooner. Thanks!

I've uploaded a standalone example: http://phot-awe.com/test/WpfCalcBinding.zip
Please let me know if it's clear enough

Thanks, it's clear enough, very slow :)

Hehe ;) glad you could repro :)

After adding cache startup was accelerated significantly. On my machine it was 20 seconds in old version and 1 second in new version. The number of created objects significantly reduced also. Very good :)

Package was already published. Test it and if you notice more problems with performance, let me know.

You rock! So far, works like a charm!
Right now, startup is pretty much instant. Brilliant!

Glad to help you :)