Note that there are some explanatory texts on larger screens.

plurals
  1. POMore efficient log filter
    primarykey
    data
    text
    <p>I have a program that displays lines from a log file.</p> <p>They are parsed and put into a class called LogLine then displayed in a datagrid</p> <p>Here is my filter function:</p> <pre><code>ICollectionView view = CollectionViewSource.GetDefaultView(this.LogView.ItemsSource); bool traceChecked = this.TraceCheckbox.IsChecked.HasValue &amp;&amp; this.TraceCheckbox.IsChecked.Value; bool debugChecked = this.DebugCheckbox.IsChecked.HasValue &amp;&amp; this.DebugCheckbox.IsChecked.Value; bool infoChecked = this.InfoCheckbox.IsChecked.HasValue &amp;&amp; this.InfoCheckbox.IsChecked.Value; bool warnChecked = this.WarnCheckbox.IsChecked.HasValue &amp;&amp; this.WarnCheckbox.IsChecked.Value; bool errorChecked = this.ErrorCheckbox.IsChecked.HasValue &amp;&amp; this.ErrorCheckbox.IsChecked.Value; string filtertext = this.TextFilterBox.Text; view.Filter = o =&gt; { LogLine line = o as LogLine; return line != null &amp;&amp; (((traceChecked &amp;&amp; line.Trace) || (debugChecked &amp;&amp; line.Debug) || (infoChecked &amp;&amp; line.Info) || (warnChecked &amp;&amp; line.Warn) || (errorChecked &amp;&amp; line.Error)) &amp;&amp; line.Message.Contains(filtertext)); }; </code></pre> <p>This function is slow, already, taking close to 5 seconds on a log with 200000 lines.</p> <p>What can be done to speed this up?</p> <p>I implemented a real ViewModel per HighCore's suggestion. This is marginally faster, but it is still taking 5-6 seconds to go threw all the lines of the ObservableCollection</p> <pre><code>ICollectionView view = CollectionViewSource.GetDefaultView(this.LogView.ItemsSource); LogViewModel lvm = (LogViewModel)this.DataContext; view.Filter = o =&gt; { LogLine line = o as LogLine; if (line == null || !line.Message.Contains(lvm.FilterText)) { return false; } switch (line.LogLevel) { case LogViewModel.LogLevel.Trace: return lvm.Trace; case LogViewModel.LogLevel.Debug: return lvm.Debug; case LogViewModel.LogLevel.Info: return lvm.Info; case LogViewModel.LogLevel.Warn: return lvm.Warn; case LogViewModel.LogLevel.Error: return lvm.Error; default: return false; } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload