简体   繁体   English

如何使用 Vue、Javascript 和 D3 高效处理更大的数据集?

[英]How to efficiently deal with a larger dataset using Vue, Javascript and D3?

I have to design and implement a visualization dashboard that runs only in the browser using Vue.js, D3 and JS.我必须使用 Vue.js、D3 和 JS 设计和实现一个仅在浏览器中运行的可视化仪表板。 The dataset, a.json file, has 48 MB.数据集 a.json 文件有 48 MB。 When I parse the file using d3.json(), then the task manager of google chrome shows me that the Javascript code uses around 450 MB of memory.当我使用 d3.json() 解析文件时,谷歌浏览器的任务管理器显示 Javascript 代码使用了大约 450 MB 的 memory。 I want to be able to efficiently update the different charts on the visualization dashboard which is possible when I hold the data object in memory.我希望能够有效地更新可视化仪表板上的不同图表,当我在 memory 中保存数据 object 时,这是可能的。

This is how I currently load the data.这就是我目前加载数据的方式。 I can then access it in the state of the Vuex store.然后我可以在 Vuex 商店的 state 中访问它。

actions: {
    loadData(state) {
      d3.json('filename.json').then((data) => {
        state.data = data;
      })
    },
}

Do you have any recommendations/common ways how I can reduce the memory usage.你有什么建议/常用方法可以减少 memory 的使用。 An obvious way would be to re-parse the.json file every time I need to access the data, but this would increase computation time.一个明显的方法是每次我需要访问数据时重新解析 .json 文件,但这会增加计算时间。

(UPDATE) (更新)

A colleague of mine found a solution to the problem and I wanted to share it with you:我的一位同事找到了解决问题的方法,我想与您分享:

When the parsed data object gets saved in the state of the Vuex store, Vue makes it reactive, such that Vue components can reactively update if the state of the Vuex store changes.当解析的数据 object 保存在 Vuex 存储的 state 中时,Vue 会使其反应,这样如果 state 的 Vue 存储更改,Vue 组件可以反应更新。

This can be avoided by这可以通过

Object.freeze(data);
state.data = data;

which makes the data object non-reactive.这使得数据 object 无反应。 The performance increase and ram usage decrease from this is significant.性能的提高和内存使用量的减少是显着的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM