From ac90d02f5a10e2f3c4df2718f39181629f2c1af9 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Wed, 14 Oct 2015 13:57:24 -0400 Subject: [PATCH] Get data object from Config service by reference, not deep clone Previously, any call to `genClusters` incurred a deep clone of the data object. In the case of large datasets (*e.g.* a ~1mb CSV file), this could result in over a second of additional processing, as well as the creation of a very large duplicate object in-memory: ![image](https://cloud.githubusercontent.com/assets/442115/10492615/049d8c66-727b-11e5-9ce7-7d835a9ac5d2.png) Altering the Config service to return the data object by reference, rather than as a deep clone, reduces the processing needed to the extent that it no longer even shows up on the profiler: ![image](https://cloud.githubusercontent.com/assets/442115/10492663/493c5a50-727b-11e5-91b8-237ec1ba3cdc.png) The total run time of `genClusters` drops by about a second in this case. Because the data should be consistent across all charts, and it is just the chart configuration that will vary on a plot-by-plot basis, passing the data by reference improves both the memory usage and the performance of the data load process. --- src/config/config.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/config.service.js b/src/config/config.service.js index 8e676dd1..6672c2a9 100644 --- a/src/config/config.service.js +++ b/src/config/config.service.js @@ -17,7 +17,7 @@ angular.module('vlui') }; Config.getData = function() { - return _.cloneDeep(Config.data); + return Config.data; }; Config.large = function() {