@fluidframework/matrix 2.0.0-internal.4.2.0 → 2.0.0-internal.4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/matrix";
8
- export declare const pkgVersion = "2.0.0-internal.4.2.0";
8
+ export declare const pkgVersion = "2.0.0-internal.4.3.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/matrix";
11
- exports.pkgVersion = "2.0.0-internal.4.2.0";
11
+ exports.pkgVersion = "2.0.0-internal.4.3.0";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.2.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.3.0\";\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/matrix";
8
- export declare const pkgVersion = "2.0.0-internal.4.2.0";
8
+ export declare const pkgVersion = "2.0.0-internal.4.3.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/matrix";
8
- export const pkgVersion = "2.0.0-internal.4.2.0";
8
+ export const pkgVersion = "2.0.0-internal.4.3.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.2.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.3.0\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/matrix",
3
- "version": "2.0.0-internal.4.2.0",
3
+ "version": "2.0.0-internal.4.3.0",
4
4
  "description": "Distributed matrix",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -33,29 +33,29 @@
33
33
  "dependencies": {
34
34
  "@fluidframework/common-definitions": "^0.20.1",
35
35
  "@fluidframework/common-utils": "^1.1.1",
36
- "@fluidframework/core-interfaces": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
37
- "@fluidframework/datastore-definitions": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
38
- "@fluidframework/merge-tree": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
36
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
37
+ "@fluidframework/datastore-definitions": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
38
+ "@fluidframework/merge-tree": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
39
39
  "@fluidframework/protocol-base": "^0.1039.1000",
40
40
  "@fluidframework/protocol-definitions": "^1.1.0",
41
- "@fluidframework/runtime-definitions": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
42
- "@fluidframework/runtime-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
43
- "@fluidframework/shared-object-base": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
44
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
41
+ "@fluidframework/runtime-definitions": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
42
+ "@fluidframework/runtime-utils": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
43
+ "@fluidframework/shared-object-base": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
44
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
45
45
  "@tiny-calc/nano": "0.0.0-alpha.5",
46
46
  "events": "^3.1.0",
47
47
  "tslib": "^1.10.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@fluid-internal/test-dds-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
50
+ "@fluid-internal/test-dds-utils": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
51
51
  "@fluid-tools/benchmark": "^0.47.0",
52
52
  "@fluid-tools/build-cli": "^0.17.0",
53
53
  "@fluidframework/build-common": "^1.1.0",
54
54
  "@fluidframework/build-tools": "^0.17.0",
55
55
  "@fluidframework/eslint-config-fluid": "^2.0.0",
56
56
  "@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.0.0-internal.4.1.0",
57
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
58
- "@fluidframework/test-runtime-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
57
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
58
+ "@fluidframework/test-runtime-utils": ">=2.0.0-internal.4.3.0 <2.0.0-internal.4.4.0",
59
59
  "@microsoft/api-extractor": "^7.34.4",
60
60
  "@tiny-calc/micro": "0.0.0-alpha.5",
61
61
  "@types/mocha": "^9.1.1",
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/matrix";
9
- export const pkgVersion = "2.0.0-internal.4.2.0";
9
+ export const pkgVersion = "2.0.0-internal.4.3.0";
@@ -1,84 +0,0 @@
1
- # BSP optimization
2
-
3
- The BSP set represents its data as a tree. But crucially, it carries
4
- no payload whatsoever. Instead, the whole information is encoded entirely
5
- in the structure of the tree.
6
-
7
- This allows us to potentially make the representation a lot more efficient.
8
- Let's consider exactly what information is stored in the tree:
9
-
10
- Each node can only have a few states. So we can give them a bit pattern:
11
-
12
- ```fsharp
13
- type Node<'Key> =
14
- | Empty // 00
15
- | Dense // 01
16
- | Left of Node<'Key> // 100
17
- | Right of Node<'Key> // 101
18
- | Both of Node<'Key> * Node<'Key> // 110
19
- | Exact of 'Key // 111
20
- ```
21
-
22
- But this lets us encode the BSP set very differently:
23
-
24
- ```fsharp
25
- type BspSet<'Key> =
26
- {
27
- Structure : BitVector
28
- Keys : 'Key list
29
- }
30
- ```
31
-
32
- ## Example
33
-
34
- ![Graph](./graphviz.svg "Graph")
35
-
36
- Currently, we encode the tree directly as an in-memory tree on the heap, i.e.:
37
-
38
- ```fsharp
39
- let tree =
40
- Both (
41
- Empty,
42
- Both (
43
- Dense,
44
- Right (
45
- Exact(1, 2))))
46
- ```
47
-
48
- But the new encoding would be a bit different:
49
-
50
- ```fsharp
51
- let newTree =
52
- {
53
- Structure = BitVector("110|00|110|01|101|111")
54
- Keys = [1, 2]
55
- }
56
- ```
57
-
58
- This encoding has very different properties w.r.t. to memory footprint and layout. The structure
59
- becomes a dense bit vector. In JavaScript, we would probably encode it as array of `number`s and
60
- use double-words from it. This way we'd get very good CPU cache behavoir, because in the vast
61
- majority of cases, the whole BSP set structure would fit into L1 cache and most likely be pre-loaded.
62
-
63
- Even though, we lose the possibility to do reference sharing, it may well be more efficient. We still
64
- can do reference sharing of the whole BSP set, because it remains immutable, but we can't share parts
65
- of the BSP set anymore.
66
-
67
- That said, the BSP set is only used to encode 1-dimensional sets in the product set, so you would expect
68
- the BSP sets in general to be fairly simple.
69
-
70
- Now the memory footprint of the BSP set is thus:
71
-
72
- - Some general overhead for the whole BSP set, i.e. object cost
73
- - Linear in the number of keys used for the exact representation.
74
- Usually tiny, because they replace whole subtrees and occur infrequently.
75
- - About 2.5 bits per node. I.e. **tiny**.
76
-
77
- All the algorithms recurse over the structure of the tree, so they should be able to run over this
78
- bit encoding as well. Chances are it would be a lot faster, but definitely consuming a lot less
79
- memory than before.
80
-
81
- ## Application
82
-
83
- If we did this change, we might be able to use raw product sets as messages inside say a shared dictionary
84
- because the payload of the messages might be small enough for that.
@@ -1,73 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><!-- Generated by graphviz version 2.40.1 (20161225.0304)
2
- --><!-- Title: G Pages: 1 --><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="217pt" height="260pt" viewBox="0.00 0.00 217.31 260.00">
3
- <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)">
4
- <title>G</title>
5
- <polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-256 213.3119,-256 213.3119,4 -4,4"/>
6
- <!-- root -->
7
- <g id="node1" class="node">
8
- <title>root</title>
9
- <ellipse fill="none" stroke="#000000" cx="75.176" cy="-234" rx="28.4127" ry="18"/>
10
- <text text-anchor="middle" x="75.176" y="-229.8" font-family="Times,serif" font-size="14.00" fill="#000000">both</text>
11
- </g>
12
- <!-- l -->
13
- <g id="node2" class="node">
14
- <title>l</title>
15
- <ellipse fill="none" stroke="#000000" cx="35.176" cy="-162" rx="35.3528" ry="18"/>
16
- <text text-anchor="middle" x="35.176" y="-157.8" font-family="Times,serif" font-size="14.00" fill="#000000">empty</text>
17
- </g>
18
- <!-- root&#45;&gt;l -->
19
- <g id="edge1" class="edge">
20
- <title>root-&gt;l</title>
21
- <path fill="none" stroke="#000000" d="M65.6965,-216.937C60.9345,-208.3654 55.0601,-197.7914 49.7407,-188.2165"/>
22
- <polygon fill="#000000" stroke="#000000" points="52.7813,-186.4825 44.8652,-179.4407 46.6622,-189.882 52.7813,-186.4825"/>
23
- </g>
24
- <!-- r -->
25
- <g id="node3" class="node">
26
- <title>r</title>
27
- <ellipse fill="none" stroke="#000000" cx="116.176" cy="-162" rx="28.4127" ry="18"/>
28
- <text text-anchor="middle" x="116.176" y="-157.8" font-family="Times,serif" font-size="14.00" fill="#000000">both</text>
29
- </g>
30
- <!-- root&#45;&gt;r -->
31
- <g id="edge2" class="edge">
32
- <title>root-&gt;r</title>
33
- <path fill="none" stroke="#000000" d="M84.8924,-216.937C89.8453,-208.2393 95.9721,-197.4799 101.4873,-187.7948"/>
34
- <polygon fill="#000000" stroke="#000000" points="104.6223,-189.3623 106.5293,-178.9405 98.5394,-185.8984 104.6223,-189.3623"/>
35
- </g>
36
- <!-- rl -->
37
- <g id="node4" class="node">
38
- <title>rl</title>
39
- <ellipse fill="none" stroke="#000000" cx="76.176" cy="-90" rx="33.045" ry="18"/>
40
- <text text-anchor="middle" x="76.176" y="-85.8" font-family="Times,serif" font-size="14.00" fill="#000000">dense</text>
41
- </g>
42
- <!-- r&#45;&gt;rl -->
43
- <g id="edge3" class="edge">
44
- <title>r-&gt;rl</title>
45
- <path fill="none" stroke="#000000" d="M106.6965,-144.937C101.9345,-136.3654 96.0601,-125.7914 90.7407,-116.2165"/>
46
- <polygon fill="#000000" stroke="#000000" points="93.7813,-114.4825 85.8652,-107.4407 87.6622,-117.882 93.7813,-114.4825"/>
47
- </g>
48
- <!-- rr -->
49
- <g id="node5" class="node">
50
- <title>rr</title>
51
- <ellipse fill="none" stroke="#000000" cx="156.176" cy="-90" rx="29.0529" ry="18"/>
52
- <text text-anchor="middle" x="156.176" y="-85.8" font-family="Times,serif" font-size="14.00" fill="#000000">right</text>
53
- </g>
54
- <!-- r&#45;&gt;rr -->
55
- <g id="edge4" class="edge">
56
- <title>r-&gt;rr</title>
57
- <path fill="none" stroke="#000000" d="M125.6554,-144.937C130.4174,-136.3654 136.2919,-125.7914 141.6112,-116.2165"/>
58
- <polygon fill="#000000" stroke="#000000" points="144.6898,-117.882 146.4867,-107.4407 138.5707,-114.4825 144.6898,-117.882"/>
59
- </g>
60
- <!-- rrr -->
61
- <g id="node6" class="node">
62
- <title>rrr</title>
63
- <ellipse fill="none" stroke="#000000" cx="156.176" cy="-18" rx="53.2723" ry="18"/>
64
- <text text-anchor="middle" x="156.176" y="-13.8" font-family="Times,serif" font-size="14.00" fill="#000000">Key: [1, 2]</text>
65
- </g>
66
- <!-- rr&#45;&gt;rrr -->
67
- <g id="edge5" class="edge">
68
- <title>rr-&gt;rrr</title>
69
- <path fill="none" stroke="#000000" d="M156.176,-71.8314C156.176,-64.131 156.176,-54.9743 156.176,-46.4166"/>
70
- <polygon fill="#000000" stroke="#000000" points="159.6761,-46.4132 156.176,-36.4133 152.6761,-46.4133 159.6761,-46.4132"/>
71
- </g>
72
- </g>
73
- </svg>
@@ -1,8 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export { SharedMatrix, SharedMatrixFactory } from "../../src";
7
- export { SparseArray2D } from "../../src/sparsearray2d";
8
- export { fill, IMatrix } from "../../test/utils";
@@ -1,48 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { run } from "hotloop";
7
-
8
- (async () => {
9
- console.group("Populated");
10
- await run([
11
- // { path: "./src/read/nativearray", args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: true } },
12
- // { path: "./src/read/map", args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: true } },
13
- {
14
- path: "./src/read/sparsearray2d",
15
- args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: true },
16
- },
17
- {
18
- path: "./src/read/matrix/contiguous",
19
- args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: true },
20
- },
21
- {
22
- path: "./src/read/matrix/fragmented",
23
- args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: true },
24
- },
25
- // { path: "./src/read/tiled", args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: true } }
26
- ]);
27
- console.groupEnd();
28
-
29
- console.group("Empty");
30
- await run([
31
- // { path: "./src/read/nativearray", args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: false } },
32
- // { path: "./src/read/map", args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: false } },
33
- {
34
- path: "./src/read/sparsearray2d",
35
- args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: false },
36
- },
37
- {
38
- path: "./src/read/matrix/contiguous",
39
- args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: false },
40
- },
41
- {
42
- path: "./src/read/matrix/fragmented",
43
- args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: false },
44
- },
45
- // { path: "./src/read/tiled", args: { row: 0, col: 0, rowCount: 256, colCount: 256, fill: false } }
46
- ]);
47
- console.groupEnd();
48
- })();
@@ -1,31 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { pointwise } from "./test";
7
-
8
- export class Map256x256<T> {
9
- private readonly cells = new Map<number, T>();
10
-
11
- public get rowCount() {
12
- return 256;
13
- }
14
- public get colCount() {
15
- return 256;
16
- }
17
-
18
- public getCell(row: number, col: number) {
19
- return this.cells.get((row << 8) + col);
20
- }
21
-
22
- public setCell(row: number, col: number, value: T) {
23
- this.cells.set((row << 8) + col, value);
24
- }
25
-
26
- public get matrixProducer() {
27
- return undefined as any;
28
- }
29
- }
30
-
31
- pointwise(undefined, new Map256x256<number>());
@@ -1,15 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { pointwise } from "../test";
7
- import { createContiguousMatrix } from "../../util";
8
- import { getTestArgs } from "hotloop";
9
-
10
- const { row, col, rowCount, colCount } = getTestArgs();
11
-
12
- const rowSize = row + rowCount;
13
- const colSize = col + colCount;
14
-
15
- pointwise(`Contiguous Matrix ${rowSize}x${colSize}`, createContiguousMatrix(rowSize, colSize));
@@ -1,12 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { pointwise } from "../test";
7
- import { createFragmentedMatrix } from "../../util";
8
- import { getTestArgs } from "hotloop";
9
-
10
- const { row, col, rowCount, colCount } = getTestArgs();
11
-
12
- pointwise("Fragmented Matrix 256x256", createFragmentedMatrix(row + rowCount, col + colCount));
@@ -1,31 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { pointwise } from "./test";
7
-
8
- export class Array256x256<T> {
9
- private readonly cells: T[] = new Array(256 * 256).fill(0);
10
-
11
- public get rowCount() {
12
- return 256;
13
- }
14
- public get colCount() {
15
- return 256;
16
- }
17
-
18
- public getCell(row: number, col: number) {
19
- return this.cells[(row << 8) + col];
20
- }
21
-
22
- public setCell(row: number, col: number, value: T) {
23
- this.cells[(row << 8) + col] = value;
24
- }
25
-
26
- public get matrixProducer() {
27
- return undefined as any;
28
- }
29
- }
30
-
31
- pointwise(undefined, new Array256x256<number>());
@@ -1,9 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { pointwise } from "./test";
7
- import { SparseArray2D } from "../imports";
8
-
9
- pointwise(undefined, new SparseArray2D());
@@ -1,30 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { benchmark, getTestArgs } from "hotloop";
7
- import { fill, IMatrix } from "../imports";
8
-
9
- const { row, col, rowCount, colCount, fill: shouldFill } = getTestArgs();
10
-
11
- export function pointwise<T>(name: string | undefined, matrix: IMatrix<T>) {
12
- if (shouldFill) {
13
- fill(matrix, row, col, rowCount, colCount);
14
- }
15
-
16
- benchmark(
17
- `SUM ${name !== undefined ? name : matrix.constructor.name} (${
18
- shouldFill ? "full" : "empty"
19
- }) Pointwise Read ${rowCount}x${colCount} @${row},${col}`,
20
- () => {
21
- let sum = 0;
22
- for (let r = row; r < rowCount; r++) {
23
- for (let c = col; c < colCount; c++) {
24
- sum += matrix.getCell(r, c) as any | 0;
25
- }
26
- }
27
- return sum;
28
- },
29
- );
30
- }
@@ -1,292 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { pointwise } from "./test";
7
-
8
- const enum Consts {
9
- logW = 4,
10
- logH = 5,
11
- w = 1 << logW,
12
- h = 1 << logH,
13
- mw = w - 1,
14
- mh = h - 1,
15
- sizeW = 1 << (4 * logW),
16
- sizeH = 1 << (4 * logH),
17
- }
18
-
19
- type CellTile<T> = T[];
20
-
21
- type SparseGrid<T> = CellTile<T>[][][];
22
-
23
- function getCell<T>(r: number, c: number, grid: SparseGrid<T>): T | undefined {
24
- if (r < 0 || c < 0 || r >= Consts.sizeH || c >= Consts.sizeW) {
25
- return undefined;
26
- }
27
- const t2 =
28
- grid[
29
- (((c >> (3 * Consts.logW)) & Consts.mw) << Consts.logH) |
30
- ((r >> (3 * Consts.logH)) & Consts.mh)
31
- ];
32
- if (t2) {
33
- const t3 =
34
- t2[
35
- (((c >> (2 * Consts.logW)) & Consts.mw) << Consts.logH) |
36
- ((r >> (2 * Consts.logH)) & Consts.mh)
37
- ];
38
- if (t3) {
39
- const t4 =
40
- t3[
41
- (((c >> Consts.logW) & Consts.mw) << Consts.logH) |
42
- ((r >> Consts.logH) & Consts.mh)
43
- ];
44
- if (t4) {
45
- return t4[((c & Consts.mw) << Consts.logH) | (r & Consts.mh)];
46
- }
47
- }
48
- }
49
- return undefined;
50
- }
51
-
52
- function setCell<T>(r: number, c: number, grid: SparseGrid<T>, value: T) {
53
- if (r < 0 || c < 0 || r >= Consts.sizeH || c >= Consts.sizeW) {
54
- return;
55
- }
56
-
57
- const i2 =
58
- (((c >> (3 * Consts.logW)) & Consts.mw) << Consts.logH) |
59
- ((r >> (3 * Consts.logH)) & Consts.mh);
60
- let t2 = grid[i2];
61
- if (t2 === undefined) {
62
- t2 = grid[i2] = [];
63
- }
64
-
65
- const i3 =
66
- (((c >> (2 * Consts.logW)) & Consts.mw) << Consts.logH) |
67
- ((r >> (2 * Consts.logH)) & Consts.mh);
68
- let t3 = t2[i3];
69
- if (t3 === undefined) {
70
- t3 = t2[i3] = [];
71
- }
72
-
73
- const i4 = (((c >> Consts.logW) & Consts.mw) << Consts.logH) | ((r >> Consts.logH) & Consts.mh);
74
- let t4 = t3[i4];
75
- if (t4 === undefined) {
76
- t4 = t3[i4] = [];
77
- }
78
- t4[((c & Consts.mw) << Consts.logH) | (r & Consts.mh)] = value;
79
- }
80
-
81
- function clearCell<T>(r: number, c: number, grid: SparseGrid<T>) {
82
- if (r < 0 || c < 0 || r >= Consts.sizeH || c >= Consts.sizeW) {
83
- return;
84
- }
85
-
86
- const i2 =
87
- (((c >> (3 * Consts.logW)) & Consts.mw) << Consts.logH) |
88
- ((r >> (3 * Consts.logH)) & Consts.mh);
89
- const t2 = grid[i2];
90
- if (t2 === undefined) {
91
- return;
92
- }
93
-
94
- const i3 =
95
- (((c >> (2 * Consts.logW)) & Consts.mw) << Consts.logH) |
96
- ((r >> (2 * Consts.logH)) & Consts.mh);
97
- const t3 = t2[i3];
98
- if (t3 === undefined) {
99
- return;
100
- }
101
-
102
- const i4 = (((c >> Consts.logW) & Consts.mw) << Consts.logH) | ((r >> Consts.logH) & Consts.mh);
103
- const t4 = t3[i4];
104
- if (t4 === undefined) {
105
- return;
106
- }
107
- delete t4[((c & Consts.mw) << Consts.logH) | (r & Consts.mh)];
108
- }
109
-
110
- function forEachCell<T>(grid: SparseGrid<T>, cb: (r: number, c: number, value: T) => void): void {
111
- let i1 = 0;
112
- for (const t1 of grid) {
113
- if (t1 !== undefined) {
114
- let i2 = 0;
115
- const c1 = (i1 >> Consts.logH) << (3 * Consts.logW);
116
- const r1 = (i1 & Consts.mh) << (3 * Consts.logH);
117
- for (const t2 of t1) {
118
- if (t2 !== undefined) {
119
- let i3 = 0;
120
- const c2 = (i2 >> Consts.logH) << (2 * Consts.logW);
121
- const r2 = (i2 & Consts.mh) << (2 * Consts.logH);
122
- for (const t3 of t2) {
123
- if (t3 !== undefined) {
124
- let i4 = 0;
125
- const c3 = (i3 >> Consts.logH) << Consts.logW;
126
- const r3 = (i3 & Consts.mh) << Consts.logH;
127
- for (const value of t3) {
128
- if (value !== undefined) {
129
- cb(
130
- r1 | r2 | r3 | (i4 & Consts.mh),
131
- c1 | c2 | c3 | (i4 >> Consts.logH),
132
- value,
133
- );
134
- }
135
- i4++;
136
- }
137
- }
138
- i3++;
139
- }
140
- }
141
- i2++;
142
- }
143
- }
144
- i1++;
145
- }
146
- }
147
-
148
- function forEachCellInColumn<T>(
149
- grid: SparseGrid<T>,
150
- column: number,
151
- cb: (r: number, c: number, value: T) => void,
152
- ): void {
153
- const colIdx1 = colIdx(column, 3);
154
- const colIdx2 = colIdx(column, 2);
155
- const colIdx3 = colIdx(column, 1);
156
- const colIdx4 = colIdx(column, 0);
157
- for (let r1 = 0; r1 < Consts.h; r1++) {
158
- const t1 = grid[colIdx1 | r1];
159
- if (t1 === undefined) {
160
- continue;
161
- }
162
- for (let r2 = 0; r2 < Consts.h; r2++) {
163
- const t2 = t1[colIdx2 | r2];
164
- if (t2 === undefined) {
165
- continue;
166
- }
167
- for (let r3 = 0; r3 < Consts.h; r3++) {
168
- const t3 = t2[colIdx3 | r3];
169
- if (t3 === undefined) {
170
- continue;
171
- }
172
- for (let r4 = 0; r4 < Consts.h; r4++) {
173
- const cell = t3[colIdx4 | r4];
174
- if (cell === undefined) {
175
- continue;
176
- }
177
- cb(
178
- ((r1 & Consts.mh) << (3 * Consts.logH)) |
179
- ((r2 & Consts.mh) << (2 * Consts.logH)) |
180
- ((r3 & Consts.mh) << Consts.logH) |
181
- (r4 & Consts.mh),
182
- column,
183
- cell as any,
184
- );
185
- }
186
- }
187
- }
188
- }
189
- }
190
-
191
- function colIdx(col: number, level: 0 | 1 | 2 | 3): number {
192
- return ((col >> (level * Consts.logW)) & Consts.mw) << Consts.logH;
193
- }
194
-
195
- function colIdxUnshifted(col: number, level: 0 | 1 | 2 | 3): number {
196
- return (col >> (level * Consts.logW)) & Consts.mw;
197
- }
198
-
199
- function forEachCellInColumns<T>(
200
- grid: SparseGrid<T>,
201
- columnStart: number,
202
- numCols: number,
203
- cb: (r: number, c: number, value: T) => void,
204
- ): void {
205
- const colEnd = columnStart + numCols - 1;
206
- for (let r1 = 0; r1 < Consts.h; r1++) {
207
- const cStart1 = colIdxUnshifted(columnStart, 3);
208
- const cEnd1 = colIdxUnshifted(colEnd, 3);
209
- for (let c1 = cStart1; c1 <= cEnd1; c1++) {
210
- const t1 = grid[(c1 << Consts.logH) | r1];
211
- if (t1 === undefined) {
212
- continue;
213
- }
214
- for (let r2 = 0; r2 < Consts.h; r2++) {
215
- const cStart2 = colIdxUnshifted(columnStart, 2);
216
- const cEnd2 = colIdxUnshifted(colEnd, 2);
217
- for (let c2 = cStart2; c2 <= cEnd2; c2++) {
218
- const t2 = t1[(c2 << Consts.logH) | r2];
219
- if (t2 === undefined) {
220
- continue;
221
- }
222
- for (let r3 = 0; r3 < Consts.h; r3++) {
223
- const cStart3 = colIdxUnshifted(columnStart, 1);
224
- const cEnd3 = colIdxUnshifted(colEnd, 1);
225
- for (let c3 = cStart3; c3 <= cEnd3; c3++) {
226
- const t3 = t2[(c3 << Consts.logH) | r3];
227
- if (t3 === undefined) {
228
- continue;
229
- }
230
- for (let r4 = 0; r4 < Consts.h; r4++) {
231
- const cStart4 = colIdxUnshifted(columnStart, 0);
232
- const cEnd4 = colIdxUnshifted(colEnd, 0);
233
- for (let c4 = cStart4; c4 <= cEnd4; c4++) {
234
- const cell = t3[(c4 << Consts.logH) | r4];
235
- if (cell === undefined) {
236
- continue;
237
- }
238
- cb(
239
- ((r1 & Consts.mh) << (3 * Consts.logH)) |
240
- ((r2 & Consts.mh) << (2 * Consts.logH)) |
241
- ((r3 & Consts.mh) << Consts.logH) |
242
- (r4 & Consts.mh),
243
- (c1 << (3 * Consts.logW)) |
244
- (c2 << (2 * Consts.logW)) |
245
- (c3 << Consts.logW) |
246
- c4,
247
- cell,
248
- );
249
- }
250
- }
251
- }
252
- }
253
- }
254
- }
255
- }
256
- }
257
- }
258
-
259
- // Remove unused warnings
260
- forEachCell;
261
- clearCell;
262
- forEachCellInColumn;
263
- forEachCellInColumns;
264
-
265
- function initGrid<T>(): SparseGrid<T> {
266
- return [];
267
- }
268
-
269
- export class TiledGrid<T> {
270
- private readonly cells: SparseGrid<T> = initGrid();
271
-
272
- public get rowCount() {
273
- return Consts.sizeH;
274
- }
275
- public get colCount() {
276
- return Consts.sizeW;
277
- }
278
-
279
- public getCell(row: number, col: number) {
280
- return getCell(row, col, this.cells);
281
- }
282
-
283
- public setCell(row: number, col: number, value: T) {
284
- setCell(row, col, this.cells, value);
285
- }
286
-
287
- public get matrixProducer() {
288
- return undefined as any;
289
- }
290
- }
291
-
292
- pointwise("TiledGrid", new TiledGrid<number>());
package/bench/src/util.ts DELETED
@@ -1,53 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils";
7
- import { SharedMatrix, SharedMatrixFactory } from "./imports";
8
- import { insertFragmented } from "../../test/utils";
9
- import process from "process";
10
-
11
- let count = 1;
12
- let cached: any;
13
-
14
- /**
15
- * Paranoid defense against dead code elimination.
16
- */
17
- export function consume(value: any) {
18
- count++;
19
- if (count >>> 0 === 0) {
20
- cached = value;
21
- }
22
- }
23
-
24
- // Prevent v8"s optimizer from identifying "cached" as an unused value.
25
- process.on("exit", () => {
26
- if (count >>> 0 === 0) {
27
- console.log(`Ignore this: ${cached}`);
28
- }
29
- });
30
-
31
- export function randomId() {
32
- return Math.random().toString(36).slice(2);
33
- }
34
-
35
- export function createMatrix() {
36
- return new SharedMatrixFactory().create(
37
- new MockFluidDataStoreRuntime(),
38
- randomId(),
39
- ) as SharedMatrix;
40
- }
41
-
42
- export function createContiguousMatrix(rowCount: number, colCount: number) {
43
- const matrix = createMatrix();
44
- matrix.insertRows(0, rowCount);
45
- matrix.insertCols(0, colCount);
46
- return matrix;
47
- }
48
-
49
- export function createFragmentedMatrix(rowCount: number, colCount: number) {
50
- const matrix = createMatrix();
51
- insertFragmented(matrix, rowCount, colCount);
52
- return matrix;
53
- }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "exclude": ["dist", "node_modules"],
4
- "compilerOptions": {
5
- "rootDir": "..",
6
- "outDir": "./dist",
7
- "types": ["node"],
8
- },
9
- "include": ["./src/**/*"],
10
- }