You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/07/08 08:14:45 UTC

[echarts] 01/01: perf(dataset): improve name-gen perf for high dim data.

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch dataset-perf
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit 8e1c0fe2d022ac2c08ae9cd2446aa85446494063
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Jul 8 16:09:31 2021 +0800

    perf(dataset): improve name-gen perf for high dim data.
---
 src/data/helper/completeDimensions.ts |  34 ++++++---
 test/dataset-performance.html         | 125 ++++++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+), 11 deletions(-)

diff --git a/src/data/helper/completeDimensions.ts b/src/data/helper/completeDimensions.ts
index 972dbc5..f95122b 100644
--- a/src/data/helper/completeDimensions.ts
+++ b/src/data/helper/completeDimensions.ts
@@ -34,6 +34,7 @@ import DataDimensionInfo from '../DataDimensionInfo';
 import List from '../List';
 import { CoordDimensionDefinition, CoordDimensionDefinitionLoose } from './createDimensions';
 
+
 /**
  * @see {module:echarts/test/ut/spec/data/completeDimensions}
  *
@@ -226,26 +227,34 @@ function completeDimensions(
     const fromZero = generateCoordCount != null;
     generateCoordCount = generateCoord ? (generateCoordCount || 1) : 0;
     const extra = generateCoord || 'value';
-
+    let coordDimNameAutoIdx = 0;
+    let dataDimNameAutoIdx = 0;
     // Set dim `name` and other `coordDim` and other props.
     for (let resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
         const resultItem = result[resultDimIdx] = result[resultDimIdx] || new DataDimensionInfo();
         const coordDim = resultItem.coordDim;
 
         if (coordDim == null) {
-            resultItem.coordDim = genName(
-                extra, coordDimNameMap, fromZero
+            const res = genName(
+                extra, coordDimNameMap, coordDimNameAutoIdx, fromZero
             );
+            coordDimNameAutoIdx = res.autoIdx;
+            resultItem.coordDim = res.name;
             resultItem.coordDimIndex = 0;
+            // Series specified generateCoord is using out.
             if (!generateCoord || generateCoordCount <= 0) {
                 resultItem.isExtraCoord = true;
             }
             generateCoordCount--;
         }
 
-        resultItem.name == null && (resultItem.name = genName(
-            resultItem.coordDim, dataDimNameMap, false
-        ));
+        if (resultItem.name == null) {
+            const res = genName(
+                resultItem.coordDim, dataDimNameMap, dataDimNameAutoIdx, false
+            );
+            resultItem.name = res.name;
+            dataDimNameAutoIdx = res.autoIdx;
+        }
 
         if (resultItem.type == null
             && (
@@ -312,17 +321,20 @@ function getDimCount(
 function genName(
     name: DimensionName,
     map: HashMap<unknown, DimensionName>,
+    autoIdx: number,
     fromZero: boolean
-): DimensionName {
-    if (fromZero || map.get(name) != null) {
-        let i = 0;
-        while (map.get(name + i) != null) {
+): { name: DimensionName, autoIdx: number } {
+    const mapData = map.data;
+    if (fromZero || mapData.hasOwnProperty(name)) {
+        let i = autoIdx || 0;
+        while (mapData.hasOwnProperty(name + i)) {
             i++;
         }
         name += i;
+        autoIdx = i;
     }
     map.set(name, true);
-    return name;
+    return { name, autoIdx };
 }
 
 export default completeDimensions;
diff --git a/test/dataset-performance.html b/test/dataset-performance.html
new file mode 100644
index 0000000..b399254
--- /dev/null
+++ b/test/dataset-performance.html
@@ -0,0 +1,125 @@
+<!DOCTYPE html>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+
+<html>
+    <head>
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1" />
+        <script src="lib/simpleRequire.js"></script>
+        <script src="lib/config.js"></script>
+        <script src="lib/jquery.min.js"></script>
+        <script src="lib/facePrint.js"></script>
+        <script src="lib/testHelper.js"></script>
+        <!-- <script src="ut/lib/canteen.js"></script> -->
+        <link rel="stylesheet" href="lib/reset.css" />
+    </head>
+    <body>
+        <style>
+        </style>
+
+
+
+        <div id="main0"></div>
+
+
+
+
+
+
+        <script>
+        require([
+            'echarts',
+            // 'map/js/china',
+            // './data/nutrients.json'
+        ], function (echarts) {
+            var option;
+            var indexes = Array.from(Array(1000), (_, i) => {
+                return `index${i}`
+            })
+            // var option = {
+            //     xAxis: {
+            //         type: 'category',
+            //         data: Array.from(Array(10), (_, i) => {
+            //             return i
+            //         })
+            //     },
+            //     yAxis: {
+            //         type: 'value'
+            //     },
+            //     series: indexes.map(index => {
+            //         return {
+            //             data: Array.from(Array(10), (_, i) => {
+            //                 return Math.random()*100
+            //             }),
+            //             type: 'line',
+            //         }
+            //     })
+            // };
+            var option = {
+                xAxis: {
+                    type: 'category',
+                },
+                yAxis: {
+                    type: 'value'
+                },
+                dataset: {
+                    dimension: ['date', ...indexes],
+                    source: Array.from(Array(10), (_, i) => {
+                        return {
+                            date: i,
+                            ...indexes.reduce((item, next) => {
+                                item[next] = Math.random()*100
+                                return item
+                            }, {})
+                        }
+                    })
+                },
+                series: indexes.map(index => {
+                    return {
+                        type: 'line',
+                        name: index,
+                        animation: false,
+                        showSymbol: false,
+                        lineStyle: {
+                            width: 0.5
+                        }
+                    }
+                })
+            };
+
+            var chart = testHelper.create(echarts, 'main0', {
+                title: [
+                    'Dataset with 10000 dimensions.',
+                    'Case from https://github.com/apache/echarts/issues/11907'
+                ],
+                option: {}
+            });
+
+            console.profile('render');
+            chart.setOption(option)
+            console.profileEnd('render');
+        });
+        </script>
+
+
+    </body>
+</html>
+

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org