SPARK-2288 improve ladder startup performance
This commit is contained in:
1 parent
489af5a703
commit
055e27f9aa
5 files changed
+54
-3
No files matched your search
@@ -94,7 +94,15 @@ namespace mbts.spark {
|
||||
public string abbreviation => _value?.abbreviation;
|
||||
public CustomOrderDefinitionImmutable definition => _algo_root?.definition ?? new CustomOrderDefinitionImmutable(new CustomOrderDefinition());
|
||||
public ObservableCollection<IAlgoSelector> child_algo_selectors => _child_algo_selectors;
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ObservableCollection<IAlgoSelector> child_algo_selectors_view {
|
||||
get {
|
||||
_value?.algo_root?.ensure_init();
|
||||
return _child_algo_selectors;
|
||||
}
|
||||
}
|
||||
public IReadOnlyObservableCollection<IAlgoParamVM> algo_params => _algo_params;
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public dynamic children_vm => _algo_root?.children_vm;
|
||||
|
||||
IAlgoVM _algo_root => _value?.algo_root;
|
||||
@@ -104,6 +112,7 @@ namespace mbts.spark {
|
||||
public void load_from(CustomOrderDefinitionImmutable value) => _algo_root?.load_from(value);
|
||||
public void load_many(IEnumerable<CustomOrderDefinitionImmutable> values) => _algo_root?.load_many(values);
|
||||
public Task<CustomOrderDefinitionImmutable?> load_from_async(CustomOrderDefinitionImmutable definition) => _algo_root is IAlgoVM vm ? vm.load_from_async(definition) : Task.FromResult<CustomOrderDefinitionImmutable?>(null);
|
||||
void IAlgoVM.ensure_init() => _value?.algo_root?.ensure_init();
|
||||
|
||||
IDisposable _set_hooks(AlgoDefinitionVM vm) {
|
||||
var algo_root_subs = new DisposableContainer();
|
||||
|
||||
@@ -7,6 +7,7 @@ using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using AlgoDef = bts.api.orderman.CustomOrderDefinition;
|
||||
@@ -46,6 +47,9 @@ namespace mbts.spark {
|
||||
public string abbreviation => display_name;
|
||||
public AlgoDefi definition => _definition.value;
|
||||
public ObservableCollection<IAlgoSelector> child_algo_selectors { get; } = new ObservableCollection<IAlgoSelector>();
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ObservableCollection<IAlgoSelector> child_algo_selectors_view => child_algo_selectors;
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public dynamic children_vm => impl?.children_vm;
|
||||
|
||||
public IReadOnlyObservableCollection<IAlgoParamVM> algo_params => _algo_params;
|
||||
@@ -56,6 +60,7 @@ namespace mbts.spark {
|
||||
public void load_many(IEnumerable<AlgoDefi> values) => impl?.load_many(values);
|
||||
public Task<AlgoDefi?> load_from_async(AlgoDefi definition) =>
|
||||
impl?.load_from_async(definition) ?? Task.FromResult<AlgoDefi?>(definition);
|
||||
void IAlgoVM.ensure_init() => impl?.ensure_init();
|
||||
|
||||
protected override void Dispose(bool disposing) =>
|
||||
_clear_impl();
|
||||
|
||||
@@ -10,6 +10,7 @@ using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
@@ -38,10 +39,23 @@ namespace mbts.spark {
|
||||
CustomOrderDefinitionImmutable definition { get; }
|
||||
IReadOnlyObservableCollection<IAlgoParamVM> algo_params { get; }
|
||||
ObservableCollection<IAlgoSelector> child_algo_selectors { get; }
|
||||
/// <see cref="child_algo_selectors_view"/> is almost completely redundant to <see cref="child_algo_selectors"/>.
|
||||
/// However, it serves a very important purpose: the first time its getter is called, lazy-initialization is performed.
|
||||
/// Therefor, callers should access <see cref="child_algo_selectors"/> for this data.
|
||||
/// <summary>
|
||||
/// This property should only be accessed by the view. The getter should trigger lazy-initialization (<see cref="ensure_init"/>) the first time it is accessed.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
ObservableCollection<IAlgoSelector> child_algo_selectors_view { get; }
|
||||
/// <summary>
|
||||
/// This property should only be accessed by the view. The getter should trigger lazy-initialization (<see cref="ensure_init"/>) the first time it is accessed.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
dynamic children_vm { get; }
|
||||
bool key_match(KeyEventArgs e);
|
||||
Task<CustomOrderDefinitionImmutable?> load_from_async(CustomOrderDefinitionImmutable definition);
|
||||
void load_many(IEnumerable<CustomOrderDefinitionImmutable> definitions);
|
||||
void ensure_init();
|
||||
}
|
||||
|
||||
interface IDynamicAlgoVMImpl {
|
||||
@@ -67,7 +81,6 @@ namespace mbts.spark {
|
||||
AlgoParamPermissions permissions { get; set; }
|
||||
void revert();
|
||||
void mark_committed();
|
||||
//void assign_to(CustomOrderDefinition target);
|
||||
}
|
||||
|
||||
interface IAlgoParamVM<T> : IAlgoParamVM {
|
||||
|
||||
@@ -120,6 +120,7 @@ namespace mbts.spark {
|
||||
readonly ObservableAutoWrapper<IAlgoSelector, AlgoSelectorData> _child_algo_selectors;
|
||||
readonly Property<bool> _is_expanded;
|
||||
readonly DeferrableActionWrapper _def_change_notifier;
|
||||
bool _is_initialized;
|
||||
SecurityInput _security_input;
|
||||
AlgoEditingPermissions _editing_permissions;
|
||||
IDisposable _pending_load;
|
||||
@@ -182,8 +183,21 @@ namespace mbts.spark {
|
||||
public OrdersModel orders_model => model;
|
||||
public OrderMetadata meta { get; }
|
||||
// child algos
|
||||
public dynamic children_vm => _children_vm;
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public dynamic children_vm {
|
||||
get {
|
||||
ensure_init();
|
||||
return _children_vm;
|
||||
}
|
||||
}
|
||||
public ObservableCollection<IAlgoSelector> child_algo_selectors => _child_algo_selectors;
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ObservableCollection<IAlgoSelector> child_algo_selectors_view {
|
||||
get {
|
||||
ensure_init();
|
||||
return _child_algo_selectors;
|
||||
}
|
||||
}
|
||||
// editing permissions
|
||||
public AlgoEditingPermissions editing_permissions { get => _editing_permissions; private set => Set(ref _editing_permissions, value); }
|
||||
// expand
|
||||
@@ -197,6 +211,7 @@ namespace mbts.spark {
|
||||
public void assign_to(AlgoDef value) {
|
||||
if (!(_descriptor.Accessor.GetValue(value) is TMutable algo))
|
||||
_descriptor.Accessor.SetValue(value, algo = new TMutable());
|
||||
ensure_init();
|
||||
foreach (var p in _auto_props)
|
||||
p.assign(algo);
|
||||
foreach (var sd in _child_algo_selector_data) {
|
||||
@@ -210,6 +225,13 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public void ensure_init() {
|
||||
if (!_is_initialized) {
|
||||
_is_initialized = true;
|
||||
sync_selectors();
|
||||
}
|
||||
}
|
||||
|
||||
public bool key_match(KeyEventArgs key) =>
|
||||
!string.IsNullOrEmpty(display_name) && key.Key == (Key.A + display_name[0] - 'A');
|
||||
|
||||
@@ -344,6 +366,8 @@ namespace mbts.spark {
|
||||
OrderDataHelper.get_child_algo_data(order_type);
|
||||
|
||||
protected void sync_selectors() {
|
||||
if (!_is_initialized)
|
||||
return;
|
||||
using (reset()) {
|
||||
foreach (var c in get_selector_datum()) {
|
||||
_children_vm[c.name] = mk_selector(c.name, c.get_child_from_impl, new Func<AlgoDefi, AlgoDefi?>(defi => {
|
||||
|
||||
@@ -1097,7 +1097,7 @@
|
||||
</usp:DynamicOrderParamTemplateSelector>
|
||||
</ItemsControl.ItemTemplateSelector>
|
||||
</ItemsControl>
|
||||
<ItemsControl Grid.Row="2" Grid.ColumnSpan="3" ItemsSource="{Binding child_algo_selectors}" IsTabStop="False">
|
||||
<ItemsControl Grid.Row="2" Grid.ColumnSpan="3" ItemsSource="{Binding child_algo_selectors_view}" IsTabStop="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<uag:AlgoPickerNodeView
|
||||
|
||||
Reference in new issue
Block a user