title: ReactiveUI - View Locator performance
body: <p>In my <code>WPF</code> application which makes use of <code>ReactiveUI</code>, I've noticed an area of poor performance.</p>
  <p>I have a view-model which contains a lot of other lightweight view-models (think 30ish). These nested view-models are simple, usually representing a button each. They're all displayed within a user control, inside an <code>ItemsControl</code> which is wired using ReactiveUI's <code>OneWayBind</code>. This means that each item is displayed using <a href="http://reactiveui.readthedocs.org/en/stable/basics/view-location/" rel="nofollow noreferrer">ViewModelViewHost</a>.</p>
  <h3>So, the problem</h3>
  <p>On my powerful desktop PC, when I navigate to this view-model, there is a noticable delay between pressing the &quot;go-to-view-model&quot; button and the view changing, around 0.5 seconds. When I run the same software on a Power-PC, the delay is nearly 4 seconds. This is a pretty big issue from an UX point of view.</p>
  <h3>What I've learned</h3>
  <p>I tried profiling and debugging my code for a long time, and found no problem areas. Zilch (note: <em>using JustMyCode in VS so ReactiveUI didn't show up</em>). I did however, find a way to remove the issue. Instead of binding to the <code>ItemsControl.ItemSource</code> with <code>OneWayBind</code>, I did so in XAML, as such:<code>ItemSource={Binding MyViewModels}</code> and setting the <code>DataTemplate</code> manually. This results in a much quicker transition.</p>
  <p>When you bind with <code>OneWayBind</code> with an <code>ItemsControl</code>, a <code>ViewModelViewHost</code> is automatically created for you, and the <code>ViewLocator</code> is used to find the view for your view-model. I'm assuming this is very slow for some reason.</p>
  <h3>Question</h3>
  <p>Is anyone aware of how I can get around this performance hit without having to manually define lots and lots of data-templates for an ItemsControl? If I have view-models of view-models of view-models, then things tend to get ugly very quickly. From my past experiences with <code>Caliburn.Micro</code>, the view-location conventions were very quick, so I'm also wondering if I'm not quite using <code>ReactiveUI</code> properly, and that there is an alternative approach which is quicker.</p>
  <p>Thank you.</p>
  <h3>TLDR;</h3>
  <p><code>ViewModelViewHost</code> as a <code>DataTemplate</code> for ~30 view-models causes views to be very sluggish when initially loaded, leaving the UI to look as if it has crashed. Is there any way to avoid this?</p>