From 1c83af11279afaba12187a655437c2bd0be08109 Mon Sep 17 00:00:00 2001 From: fuwa Date: Thu, 28 Nov 2019 18:38:22 +0800 Subject: [PATCH] use view cache to increase render performance --- cyberwow/lib/controller/rpc/rpc.dart | 2 +- cyberwow/lib/controller/rpc/rpcView.dart | 19 ++++++++++++++++--- cyberwow/lib/helper.dart | 1 - cyberwow/lib/state.dart | 16 ++++++++++++++-- cyberwow/lib/widget/synced.dart | 12 ++++++------ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/cyberwow/lib/controller/rpc/rpc.dart b/cyberwow/lib/controller/rpc/rpc.dart index fa74c6b..d459ab6 100644 --- a/cyberwow/lib/controller/rpc/rpc.dart +++ b/cyberwow/lib/controller/rpc/rpc.dart @@ -120,7 +120,7 @@ Future> getConnectionsSimple() async { } ); - return _sortedConn.map(rpcView.getConnectionView).map(cleanKey).toList(); + return _sortedConn.map(rpcView.getConnectionView).toList(); } diff --git a/cyberwow/lib/controller/rpc/rpcView.dart b/cyberwow/lib/controller/rpc/rpcView.dart index 613711d..28cde8a 100644 --- a/cyberwow/lib/controller/rpc/rpcView.dart +++ b/cyberwow/lib/controller/rpc/rpcView.dart @@ -122,7 +122,7 @@ Map simpleHeight(int height, Map x) { } else if (v < height) { - return MapEntry(k, '- ${height - v}'); + return MapEntry(k, '-${height - v}'); } else if (v == height) { @@ -130,7 +130,7 @@ Map simpleHeight(int height, Map x) { } else { - return MapEntry(k, '+ ${v - height}'); + return MapEntry(k, '+${v - height}'); } } else { @@ -162,7 +162,7 @@ Map getInfoView(Map x) { (k,v) => _remove.contains(k) ); - return _filteredInfo.map + final _formattedInfo = _filteredInfo.map ( (k, v) { if (k == 'top_block_hash') { @@ -197,6 +197,19 @@ Map getInfoView(Map x) { } + else { + return MapEntry(k, v); + } + } + ); + + return _formattedInfo.map + ( + (k, v) { + if (k.contains('_count') && k != 'tx_count') { + return MapEntry(k.replaceAll('_count', ''), v); + } + else { return MapEntry(k, v); } diff --git a/cyberwow/lib/helper.dart b/cyberwow/lib/helper.dart index 6f907dd..c9b8ea6 100644 --- a/cyberwow/lib/helper.dart +++ b/cyberwow/lib/helper.dart @@ -41,7 +41,6 @@ Map cleanKey(Map x) { k .replaceAll('cumulative', 'Σ') .replaceAll('current_', '') - .replaceAll('_count', '') .replaceAll('_', ' ') , v diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 13da4fb..1f32e13 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -36,7 +36,8 @@ import 'controller/daemon.dart' as daemon; import 'controller/refresh.dart' as refresh; import 'config.dart' as config; import 'logging.dart'; -import 'controller/rpc/rpcView.dart'; +import 'helper.dart'; +import 'controller/rpc/rpcView.dart' as rpcView; abstract class AppState { T use @@ -243,6 +244,10 @@ class SyncedState extends HookedState { String syncInfo = 'syncInfo'; PageController pageController; + String getInfoCache = ''; + String getConnectionsCache = ''; + String getTransactionPoolCache = ''; + SyncedState(f1, f2, f3, this.stdout, this.processInput, this.processOutput, this.pageIndex) : super (f1, f2, f3) { pageController = PageController( initialPage: pageIndex ); @@ -300,12 +305,19 @@ class SyncedState extends HookedState { height = await rpc.height(); connected = await daemon.isConnected(); getInfo = await rpc.getInfoSimple(); + getInfoCache = pretty(getInfo); + final _getConnections = await rpc.getConnectionsSimple(); - getConnections = _getConnections.map((x) => simpleHeight(height, x)).toList(); + getConnections = _getConnections + .map((x) => rpcView.simpleHeight(height, x)) + .map(cleanKey) + .toList(); + getConnectionsCache = pretty(getConnections); // getTransactionPool = await rpc.getTransactionPoolString(); getTransactionPool = await rpc.getTransactionPoolSimple(); + getTransactionPoolCache = pretty(getTransactionPool); // appendInput('help'); diff --git a/cyberwow/lib/widget/synced.dart b/cyberwow/lib/widget/synced.dart index e239e99..f5d25ba 100644 --- a/cyberwow/lib/widget/synced.dart +++ b/cyberwow/lib/widget/synced.dart @@ -88,7 +88,7 @@ Widget summary(BuildContext context, SyncedState state) { ); } -Widget rpcView(BuildContext context, String title, dynamic body) { +Widget rpcView(BuildContext context, String title, String body) { return Container ( padding: const EdgeInsets.all(10.0), @@ -127,7 +127,7 @@ Widget rpcView(BuildContext context, String title, dynamic body) { ), Text ( - pretty(body), + body, style: Theme.of(context).textTheme.body2, ) ], @@ -140,21 +140,21 @@ Widget rpcView(BuildContext context, String title, dynamic body) { ); } -Widget getInfo(BuildContext context, SyncedState state) => rpcView(context, 'info', state.getInfo); -Widget syncInfo(BuildContext context, SyncedState state) => rpcView(context, 'sync info', state.syncInfo); +Widget getInfo(BuildContext context, SyncedState state) => rpcView(context, 'info', state.getInfoCache); +Widget syncInfo(BuildContext context, SyncedState state) => rpcView(context, 'sync info', pretty(state.syncInfo)); Widget getTransactionPool(BuildContext context, SyncedState state) { final pool = state.getTransactionPool; const minimalLength = 6; final subTitle = pool.length < minimalLength ? '' : ' ‹${pool.length}›'; - return rpcView(context, 'tx pool' + subTitle, pool); + return rpcView(context, 'tx pool' + subTitle, state.getTransactionPoolCache); } Widget getConnections(BuildContext context, SyncedState state) { final peers = state.getConnections; const minimalLength = 6; final subTitle = peers.length < minimalLength ? '' : ' ‹${peers.length}›'; - return rpcView(context, 'peers' + subTitle, peers); + return rpcView(context, 'peers' + subTitle, state.getConnectionsCache); }