@fluidframework/id-compressor 2.0.0-rc.1.0.4 → 2.0.0-rc.2.0.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.
Files changed (264) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +5 -5
  2. package/{.mocharc.js → .mocharc.cjs} +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
  5. package/api-extractor-lint.json +1 -1
  6. package/api-extractor.json +1 -1
  7. package/api-report/id-compressor.api.md +5 -42
  8. package/dist/finalSpace.d.ts +2 -2
  9. package/dist/finalSpace.d.ts.map +1 -1
  10. package/dist/finalSpace.js +4 -4
  11. package/dist/finalSpace.js.map +1 -1
  12. package/dist/id-compressor-alpha.d.ts +117 -112
  13. package/dist/id-compressor-beta.d.ts +84 -77
  14. package/dist/id-compressor-public.d.ts +84 -77
  15. package/dist/id-compressor-untrimmed.d.ts +117 -112
  16. package/dist/idCompressor.d.ts +15 -19
  17. package/dist/idCompressor.d.ts.map +1 -1
  18. package/dist/idCompressor.js +107 -94
  19. package/dist/idCompressor.js.map +1 -1
  20. package/dist/identifiers.d.ts +1 -1
  21. package/dist/identifiers.d.ts.map +1 -1
  22. package/dist/identifiers.js.map +1 -1
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +9 -10
  26. package/dist/index.js.map +1 -1
  27. package/dist/package.json +3 -0
  28. package/dist/packageVersion.d.ts +1 -1
  29. package/dist/packageVersion.js +1 -1
  30. package/dist/packageVersion.js.map +1 -1
  31. package/dist/persistanceUtilities.d.ts +1 -1
  32. package/dist/persistanceUtilities.d.ts.map +1 -1
  33. package/dist/persistanceUtilities.js.map +1 -1
  34. package/dist/sessionSpaceNormalizer.d.ts +2 -2
  35. package/dist/sessionSpaceNormalizer.d.ts.map +1 -1
  36. package/dist/sessionSpaceNormalizer.js +4 -4
  37. package/dist/sessionSpaceNormalizer.js.map +1 -1
  38. package/dist/sessions.d.ts +2 -2
  39. package/dist/sessions.d.ts.map +1 -1
  40. package/dist/sessions.js +12 -12
  41. package/dist/sessions.js.map +1 -1
  42. package/dist/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
  43. package/dist/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
  44. package/dist/test/appendOnlySortedMap.perf.spec.js.map +1 -0
  45. package/dist/test/appendOnlySortedMap.spec.d.ts +6 -0
  46. package/dist/test/appendOnlySortedMap.spec.d.ts.map +1 -0
  47. package/dist/test/appendOnlySortedMap.spec.js.map +1 -0
  48. package/dist/test/idCompressor.perf.spec.d.ts +6 -0
  49. package/dist/test/idCompressor.perf.spec.d.ts.map +1 -0
  50. package/dist/test/idCompressor.perf.spec.js.map +1 -0
  51. package/dist/test/idCompressor.spec.d.ts +6 -0
  52. package/dist/test/idCompressor.spec.d.ts.map +1 -0
  53. package/dist/test/idCompressor.spec.js.map +1 -0
  54. package/dist/test/idCompressorTestUtilities.d.ts +245 -0
  55. package/dist/test/idCompressorTestUtilities.d.ts.map +1 -0
  56. package/dist/test/idCompressorTestUtilities.js +589 -0
  57. package/dist/test/idCompressorTestUtilities.js.map +1 -0
  58. package/dist/test/index.d.ts +9 -0
  59. package/dist/test/index.d.ts.map +1 -0
  60. package/dist/test/index.js +13 -0
  61. package/dist/test/index.js.map +1 -0
  62. package/dist/test/numericUuid.spec.d.ts +6 -0
  63. package/dist/test/numericUuid.spec.d.ts.map +1 -0
  64. package/dist/test/numericUuid.spec.js.map +1 -0
  65. package/dist/test/sessionSpaceNormalizer.spec.d.ts +6 -0
  66. package/dist/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
  67. package/dist/test/sessionSpaceNormalizer.spec.js.map +1 -0
  68. package/dist/test/snapshots/dirname.cjs +16 -0
  69. package/dist/test/snapshots/dirname.cjs.map +1 -0
  70. package/dist/test/snapshots/dirname.d.cts +6 -0
  71. package/dist/test/snapshots/dirname.d.cts.map +1 -0
  72. package/{lib/types/idCompressor.mjs → dist/test/snapshots/summary.spec.d.ts} +1 -1
  73. package/dist/test/snapshots/summary.spec.d.ts.map +1 -0
  74. package/dist/test/snapshots/summary.spec.js.map +1 -0
  75. package/dist/test/testCommon.d.ts +90 -0
  76. package/dist/test/testCommon.d.ts.map +1 -0
  77. package/dist/test/testCommon.js +90 -0
  78. package/dist/test/testCommon.js.map +1 -0
  79. package/dist/tsdoc-metadata.json +1 -1
  80. package/dist/types/idCompressor.d.ts +134 -67
  81. package/dist/types/idCompressor.d.ts.map +1 -1
  82. package/dist/types/idCompressor.js.map +1 -1
  83. package/dist/types/index.d.ts +3 -3
  84. package/dist/types/index.d.ts.map +1 -1
  85. package/dist/types/index.js.map +1 -1
  86. package/dist/types/persisted-types/0.0.1.d.ts +1 -1
  87. package/dist/types/persisted-types/0.0.1.d.ts.map +1 -1
  88. package/dist/types/persisted-types/0.0.1.js.map +1 -1
  89. package/dist/types/persisted-types/index.d.ts +1 -1
  90. package/dist/types/persisted-types/index.d.ts.map +1 -1
  91. package/dist/types/persisted-types/index.js.map +1 -1
  92. package/dist/utilities.d.ts +2 -2
  93. package/dist/utilities.d.ts.map +1 -1
  94. package/dist/utilities.js.map +1 -1
  95. package/lib/{appendOnlySortedMap.d.mts → appendOnlySortedMap.d.ts} +1 -1
  96. package/lib/appendOnlySortedMap.d.ts.map +1 -0
  97. package/lib/{appendOnlySortedMap.mjs → appendOnlySortedMap.js} +3 -1
  98. package/lib/appendOnlySortedMap.js.map +1 -0
  99. package/lib/{finalSpace.d.mts → finalSpace.d.ts} +3 -3
  100. package/lib/finalSpace.d.ts.map +1 -0
  101. package/lib/{finalSpace.mjs → finalSpace.js} +2 -2
  102. package/lib/finalSpace.js.map +1 -0
  103. package/lib/{id-compressor-alpha.d.mts → id-compressor-alpha.d.ts} +117 -112
  104. package/lib/id-compressor-beta.d.ts +179 -0
  105. package/lib/id-compressor-public.d.ts +179 -0
  106. package/lib/{id-compressor-untrimmed.d.mts → id-compressor-untrimmed.d.ts} +117 -112
  107. package/lib/{idCompressor.d.mts → idCompressor.d.ts} +16 -20
  108. package/lib/idCompressor.d.ts.map +1 -0
  109. package/lib/{idCompressor.mjs → idCompressor.js} +54 -41
  110. package/lib/idCompressor.js.map +1 -0
  111. package/lib/{identifiers.d.mts → identifiers.d.ts} +2 -2
  112. package/lib/identifiers.d.ts.map +1 -0
  113. package/lib/{identifiers.mjs → identifiers.js} +1 -1
  114. package/lib/identifiers.js.map +1 -0
  115. package/lib/{index.d.mts → index.d.ts} +7 -4
  116. package/lib/index.d.ts.map +1 -0
  117. package/lib/index.js +10 -0
  118. package/lib/index.js.map +1 -0
  119. package/lib/{packageVersion.d.mts → packageVersion.d.ts} +2 -2
  120. package/lib/packageVersion.d.ts.map +1 -0
  121. package/lib/{packageVersion.mjs → packageVersion.js} +2 -2
  122. package/lib/packageVersion.js.map +1 -0
  123. package/lib/{persistanceUtilities.d.mts → persistanceUtilities.d.ts} +2 -2
  124. package/lib/persistanceUtilities.d.ts.map +1 -0
  125. package/lib/{persistanceUtilities.mjs → persistanceUtilities.js} +1 -1
  126. package/lib/persistanceUtilities.js.map +1 -0
  127. package/lib/{sessionSpaceNormalizer.d.mts → sessionSpaceNormalizer.d.ts} +3 -3
  128. package/lib/sessionSpaceNormalizer.d.ts.map +1 -0
  129. package/lib/{sessionSpaceNormalizer.mjs → sessionSpaceNormalizer.js} +3 -3
  130. package/lib/sessionSpaceNormalizer.js.map +1 -0
  131. package/lib/{sessions.d.mts → sessions.d.ts} +3 -3
  132. package/lib/sessions.d.ts.map +1 -0
  133. package/lib/{sessions.mjs → sessions.js} +2 -2
  134. package/lib/sessions.js.map +1 -0
  135. package/lib/test/appendOnlySortedMap.perf.spec.d.ts +6 -0
  136. package/lib/test/appendOnlySortedMap.perf.spec.d.ts.map +1 -0
  137. package/lib/test/appendOnlySortedMap.perf.spec.js +49 -0
  138. package/lib/test/appendOnlySortedMap.perf.spec.js.map +1 -0
  139. package/lib/test/appendOnlySortedMap.spec.d.ts +6 -0
  140. package/lib/test/appendOnlySortedMap.spec.d.ts.map +1 -0
  141. package/lib/test/appendOnlySortedMap.spec.js +166 -0
  142. package/lib/test/appendOnlySortedMap.spec.js.map +1 -0
  143. package/lib/test/idCompressor.perf.spec.d.ts +6 -0
  144. package/lib/test/idCompressor.perf.spec.d.ts.map +1 -0
  145. package/lib/test/idCompressor.perf.spec.js +281 -0
  146. package/lib/test/idCompressor.perf.spec.js.map +1 -0
  147. package/lib/test/idCompressor.spec.d.ts +6 -0
  148. package/lib/test/idCompressor.spec.d.ts.map +1 -0
  149. package/lib/test/idCompressor.spec.js +953 -0
  150. package/lib/test/idCompressor.spec.js.map +1 -0
  151. package/lib/test/idCompressorTestUtilities.d.ts +245 -0
  152. package/lib/test/idCompressorTestUtilities.d.ts.map +1 -0
  153. package/lib/test/idCompressorTestUtilities.js +576 -0
  154. package/lib/test/idCompressorTestUtilities.js.map +1 -0
  155. package/lib/test/index.d.ts +9 -0
  156. package/lib/test/index.d.ts.map +1 -0
  157. package/lib/test/index.js +9 -0
  158. package/lib/test/index.js.map +1 -0
  159. package/lib/test/numericUuid.spec.d.ts +6 -0
  160. package/lib/test/numericUuid.spec.d.ts.map +1 -0
  161. package/lib/test/numericUuid.spec.js +74 -0
  162. package/lib/test/numericUuid.spec.js.map +1 -0
  163. package/lib/test/sessionSpaceNormalizer.spec.d.ts +6 -0
  164. package/lib/test/sessionSpaceNormalizer.spec.d.ts.map +1 -0
  165. package/lib/test/sessionSpaceNormalizer.spec.js +43 -0
  166. package/lib/test/sessionSpaceNormalizer.spec.js.map +1 -0
  167. package/lib/test/snapshots/dirname.cjs +16 -0
  168. package/lib/test/snapshots/dirname.cjs.map +1 -0
  169. package/lib/test/snapshots/dirname.d.cts +6 -0
  170. package/lib/test/snapshots/dirname.d.cts.map +1 -0
  171. package/lib/test/snapshots/summary.spec.d.ts +6 -0
  172. package/lib/test/snapshots/summary.spec.d.ts.map +1 -0
  173. package/lib/test/snapshots/summary.spec.js +127 -0
  174. package/lib/test/snapshots/summary.spec.js.map +1 -0
  175. package/lib/test/testCommon.d.ts +90 -0
  176. package/lib/test/testCommon.d.ts.map +1 -0
  177. package/lib/test/testCommon.js +80 -0
  178. package/lib/test/testCommon.js.map +1 -0
  179. package/lib/types/{idCompressor.d.mts → idCompressor.d.ts} +135 -68
  180. package/lib/types/idCompressor.d.ts.map +1 -0
  181. package/lib/types/{identifiers.mjs → idCompressor.js} +1 -1
  182. package/lib/types/idCompressor.js.map +1 -0
  183. package/lib/types/{identifiers.d.mts → identifiers.d.ts} +1 -1
  184. package/lib/types/identifiers.d.ts.map +1 -0
  185. package/lib/types/identifiers.js +6 -0
  186. package/lib/types/identifiers.js.map +1 -0
  187. package/lib/types/{index.d.mts → index.d.ts} +4 -4
  188. package/lib/types/index.d.ts.map +1 -0
  189. package/lib/types/{persisted-types/0.0.1.mjs → index.js} +1 -1
  190. package/lib/types/index.js.map +1 -0
  191. package/lib/types/persisted-types/{0.0.1.d.mts → 0.0.1.d.ts} +2 -2
  192. package/lib/types/persisted-types/0.0.1.d.ts.map +1 -0
  193. package/lib/types/persisted-types/{index.mjs → 0.0.1.js} +1 -1
  194. package/lib/types/persisted-types/0.0.1.js.map +1 -0
  195. package/lib/types/persisted-types/{index.d.mts → index.d.ts} +2 -2
  196. package/lib/types/persisted-types/index.d.ts.map +1 -0
  197. package/lib/types/{index.mjs → persisted-types/index.js} +1 -1
  198. package/lib/types/persisted-types/index.js.map +1 -0
  199. package/lib/{utilities.d.mts → utilities.d.ts} +3 -3
  200. package/lib/utilities.d.ts.map +1 -0
  201. package/lib/{utilities.mjs → utilities.js} +2 -1
  202. package/lib/utilities.js.map +1 -0
  203. package/package.json +87 -21
  204. package/src/finalSpace.ts +2 -2
  205. package/src/idCompressor.ts +75 -59
  206. package/src/identifiers.ts +1 -1
  207. package/src/index.ts +3 -3
  208. package/src/packageVersion.ts +1 -1
  209. package/src/persistanceUtilities.ts +1 -1
  210. package/src/sessionSpaceNormalizer.ts +3 -3
  211. package/src/sessions.ts +3 -3
  212. package/src/test/idCompressorTestUtilities.ts +921 -0
  213. package/src/test/index.ts +10 -0
  214. package/src/test/snapshots/dirname.cts +13 -0
  215. package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client +1 -0
  216. package/src/test/snapshots/files/compressor-with-finalized-range-from-one-client-client2 +1 -0
  217. package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients +1 -0
  218. package/src/test/snapshots/files/compressors-with-finalized-ranges-from-two-clients-client2 +1 -0
  219. package/src/test/snapshots/files/empty-compressor-summary +1 -0
  220. package/src/test/snapshots/files/expansion-semantics +1 -0
  221. package/src/test/snapshots/files/expansion-semantics-client2 +1 -0
  222. package/src/test/testCommon.ts +143 -0
  223. package/src/test/tsconfig.cjs.json +12 -0
  224. package/src/test/tsconfig.json +20 -0
  225. package/src/types/idCompressor.ts +147 -72
  226. package/src/types/index.ts +8 -3
  227. package/src/types/persisted-types/0.0.1.ts +1 -1
  228. package/src/types/persisted-types/index.ts +1 -1
  229. package/src/utilities.ts +2 -2
  230. package/tsconfig.cjs.json +7 -0
  231. package/tsconfig.json +2 -5
  232. package/lib/appendOnlySortedMap.d.mts.map +0 -1
  233. package/lib/appendOnlySortedMap.mjs.map +0 -1
  234. package/lib/finalSpace.d.mts.map +0 -1
  235. package/lib/finalSpace.mjs.map +0 -1
  236. package/lib/id-compressor-beta.d.mts +0 -172
  237. package/lib/id-compressor-public.d.mts +0 -172
  238. package/lib/idCompressor.d.mts.map +0 -1
  239. package/lib/idCompressor.mjs.map +0 -1
  240. package/lib/identifiers.d.mts.map +0 -1
  241. package/lib/identifiers.mjs.map +0 -1
  242. package/lib/index.d.mts.map +0 -1
  243. package/lib/index.mjs +0 -7
  244. package/lib/index.mjs.map +0 -1
  245. package/lib/packageVersion.d.mts.map +0 -1
  246. package/lib/packageVersion.mjs.map +0 -1
  247. package/lib/persistanceUtilities.d.mts.map +0 -1
  248. package/lib/persistanceUtilities.mjs.map +0 -1
  249. package/lib/sessionSpaceNormalizer.d.mts.map +0 -1
  250. package/lib/sessionSpaceNormalizer.mjs.map +0 -1
  251. package/lib/sessions.d.mts.map +0 -1
  252. package/lib/sessions.mjs.map +0 -1
  253. package/lib/types/idCompressor.d.mts.map +0 -1
  254. package/lib/types/idCompressor.mjs.map +0 -1
  255. package/lib/types/identifiers.d.mts.map +0 -1
  256. package/lib/types/identifiers.mjs.map +0 -1
  257. package/lib/types/index.d.mts.map +0 -1
  258. package/lib/types/index.mjs.map +0 -1
  259. package/lib/types/persisted-types/0.0.1.d.mts.map +0 -1
  260. package/lib/types/persisted-types/0.0.1.mjs.map +0 -1
  261. package/lib/types/persisted-types/index.d.mts.map +0 -1
  262. package/lib/types/persisted-types/index.mjs.map +0 -1
  263. package/lib/utilities.d.mts.map +0 -1
  264. package/lib/utilities.mjs.map +0 -1
@@ -0,0 +1,281 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
6
+ import { benchmark, BenchmarkType } from "@fluid-tools/benchmark";
7
+ import { assert } from "@fluidframework/core-utils";
8
+ import { take } from "@fluid-private/stochastic-test-utils";
9
+ import { IdCompressor } from "../idCompressor.js";
10
+ import { createSessionId } from "../utilities.js";
11
+ import { isFinalId, isLocalId, fail } from "./testCommon.js";
12
+ import { Client, DestinationClient, IdCompressorTestNetwork, buildHugeCompressor, makeOpGenerator, performFuzzActions, sessionIds, } from "./idCompressorTestUtilities.js";
13
+ const initialClusterCapacity = 512;
14
+ describe("IdCompressor Perf", () => {
15
+ const type = BenchmarkType.Measurement;
16
+ const localClient = Client.Client1;
17
+ const remoteClient = Client.Client2;
18
+ let perfCompressor;
19
+ function setupCompressors(clusterSize, localClientCanEdit, synchronizeAtEnd) {
20
+ const perfNetwork = new IdCompressorTestNetwork(clusterSize);
21
+ const maxClusterSize = clusterSize * 2;
22
+ const generator = take(1000, makeOpGenerator({
23
+ validateInterval: 2000,
24
+ maxClusterSize,
25
+ outsideAllocationFraction: 0.9,
26
+ }));
27
+ performFuzzActions(generator, perfNetwork, Math.E, localClientCanEdit ? undefined : localClient, synchronizeAtEnd);
28
+ perfCompressor = perfNetwork.getCompressorUnsafeNoProxy(localClient);
29
+ return perfNetwork;
30
+ }
31
+ function getIdMadeBy(client, eagerFinal, network) {
32
+ const log = network.getIdLog(client);
33
+ for (let i = log.length - 1; i > 0; i--) {
34
+ const { id, originatingClient } = log[i];
35
+ if (originatingClient === client) {
36
+ if ((eagerFinal && isFinalId(id)) || (!eagerFinal && isLocalId(id))) {
37
+ assert(eagerFinal === isFinalId(id), "Not local/final as requested.");
38
+ return id;
39
+ }
40
+ }
41
+ }
42
+ fail("no ID found in log");
43
+ }
44
+ function benchmarkWithFlag(creator) {
45
+ for (const flag of [true, false]) {
46
+ creator(flag);
47
+ }
48
+ }
49
+ benchmark({
50
+ type,
51
+ title: `allocate local ID`,
52
+ before: () => {
53
+ setupCompressors(initialClusterCapacity, true, true);
54
+ },
55
+ benchmarkFn: () => {
56
+ perfCompressor.generateCompressedId();
57
+ },
58
+ });
59
+ benchmark({
60
+ type,
61
+ title: "take an ID creation range",
62
+ before: () => {
63
+ setupCompressors(initialClusterCapacity, true, true);
64
+ },
65
+ benchmarkFn: () => {
66
+ perfCompressor.generateCompressedId();
67
+ perfCompressor.takeNextCreationRange();
68
+ },
69
+ });
70
+ for (const clusterSize of [1, 10, 500, 1000]) {
71
+ const numIds = 7;
72
+ const session1 = "8150a099-5302-4672-b5f3-7a4492b59418";
73
+ const session2 = "f2ded886-92da-4248-967b-eb96ee04cf51";
74
+ let session = session1;
75
+ let nextFirstFinalizedGenCount1 = 1;
76
+ let nextFirstFinalizedGenCount2 = 1;
77
+ benchmark({
78
+ type,
79
+ title: `finalize a range of IDs (cluster size = ${clusterSize})`,
80
+ before: () => {
81
+ setupCompressors(clusterSize, false, true);
82
+ },
83
+ benchmarkFn: () => {
84
+ // Create a range with as minimal overhead as possible, as we'd like for this code to not exist
85
+ // in the timing loop at all (but benchmark forces us to do so)
86
+ const isFirstClient = session === session1;
87
+ const firstGenCount = isFirstClient
88
+ ? nextFirstFinalizedGenCount1
89
+ : nextFirstFinalizedGenCount2;
90
+ const range = {
91
+ sessionId: session,
92
+ ids: {
93
+ firstGenCount,
94
+ count: numIds,
95
+ requestedClusterSize: initialClusterCapacity,
96
+ },
97
+ };
98
+ perfCompressor.finalizeCreationRange(range);
99
+ const lastGenCount = firstGenCount + numIds;
100
+ if (isFirstClient) {
101
+ nextFirstFinalizedGenCount1 = lastGenCount;
102
+ }
103
+ else {
104
+ nextFirstFinalizedGenCount2 = lastGenCount;
105
+ }
106
+ // Alternate clients to sidestep optimization that packs them all into last cluster
107
+ session = isFirstClient ? session1 : session2;
108
+ },
109
+ });
110
+ }
111
+ benchmarkWithFlag((isLocal) => {
112
+ const remoteSessionId = sessionIds.get(remoteClient);
113
+ let opSpaceId;
114
+ benchmark({
115
+ type,
116
+ title: `normalize a ${isLocal ? "local" : "final"} ID from a remote session to session space`,
117
+ before: () => {
118
+ const network = setupCompressors(initialClusterCapacity, true, true);
119
+ const remoteSession = getIdMadeBy(remoteClient, false, network);
120
+ opSpaceId = (isLocal
121
+ ? remoteSession
122
+ : network.getCompressor(remoteClient).normalizeToOpSpace(remoteSession));
123
+ },
124
+ benchmarkFn: () => {
125
+ perfCompressor.normalizeToSessionSpace(opSpaceId, remoteSessionId);
126
+ },
127
+ });
128
+ });
129
+ benchmarkWithFlag((eagerFinal) => {
130
+ let id;
131
+ benchmark({
132
+ type,
133
+ title: `normalize a final ID corresponding to a ${eagerFinal ? "eager final" : "local"} ID from op space to the local session`,
134
+ before: () => {
135
+ const network = setupCompressors(initialClusterCapacity, true, true);
136
+ const opId = perfCompressor.normalizeToOpSpace(getIdMadeBy(localClient, eagerFinal, network));
137
+ assert(isFinalId(opId), "Must be final");
138
+ id = opId;
139
+ },
140
+ benchmarkFn: () => {
141
+ perfCompressor.normalizeToSessionSpace(id, perfCompressor.localSessionId);
142
+ },
143
+ });
144
+ });
145
+ benchmarkWithFlag((isLocalOriginator) => {
146
+ const remoteSessionId = sessionIds.get(remoteClient);
147
+ let opSpaceId;
148
+ benchmark({
149
+ type,
150
+ title: `normalize a final ID from a ${isLocalOriginator ? "local" : "remote"} session to a small session space (common case)`,
151
+ before: () => {
152
+ const network = setupCompressors(initialClusterCapacity, false, true);
153
+ // Ensure the local session has several different clusters
154
+ for (let clusterCount = 0; clusterCount < 5; clusterCount++) {
155
+ network.allocateAndSendIds(localClient,
156
+ // eslint-disable-next-line @typescript-eslint/dot-notation
157
+ perfCompressor["nextRequestedClusterSize"]);
158
+ network.allocateAndSendIds(remoteClient,
159
+ // eslint-disable-next-line @typescript-eslint/dot-notation
160
+ perfCompressor["nextRequestedClusterSize"] * 2);
161
+ network.deliverOperations(DestinationClient.All);
162
+ }
163
+ const client = isLocalOriginator ? localClient : remoteClient;
164
+ const idFromSession = getIdMadeBy(client, true, network);
165
+ opSpaceId = network.getCompressor(client).normalizeToOpSpace(idFromSession);
166
+ },
167
+ benchmarkFn: () => {
168
+ perfCompressor.normalizeToSessionSpace(opSpaceId, remoteSessionId);
169
+ },
170
+ });
171
+ });
172
+ let unackedLocalId;
173
+ benchmark({
174
+ type,
175
+ title: `normalize an unacked local ID from the local session to op space`,
176
+ before: () => {
177
+ const network = setupCompressors(initialClusterCapacity, true, false);
178
+ // Ensure no eager finals
179
+ network.allocateAndSendIds(localClient,
180
+ // eslint-disable-next-line @typescript-eslint/dot-notation
181
+ network.getCompressor(localClient)["nextRequestedClusterSize"] * 2 + 1);
182
+ unackedLocalId = getIdMadeBy(localClient, false, network);
183
+ assert(perfCompressor.normalizeToOpSpace(unackedLocalId) === unackedLocalId, "Local was acked.");
184
+ },
185
+ benchmarkFn: () => {
186
+ perfCompressor.normalizeToOpSpace(unackedLocalId);
187
+ },
188
+ });
189
+ benchmarkWithFlag((eagerFinal) => {
190
+ let id;
191
+ benchmark({
192
+ type,
193
+ title: `normalize an acked ${eagerFinal ? "eager final" : "local"} ID from the local session to op space`,
194
+ before: () => {
195
+ const network = setupCompressors(initialClusterCapacity, true, true);
196
+ id = getIdMadeBy(localClient, eagerFinal, network);
197
+ },
198
+ benchmarkFn: () => {
199
+ perfCompressor.normalizeToOpSpace(id);
200
+ },
201
+ });
202
+ });
203
+ benchmarkWithFlag((local) => {
204
+ let finalIdToDecompress;
205
+ benchmark({
206
+ type,
207
+ title: `decompress a final ID from a ${local ? "local" : "remote"} client into a stable ID`,
208
+ before: () => {
209
+ const network = setupCompressors(initialClusterCapacity, true, true);
210
+ finalIdToDecompress = getIdMadeBy(local ? localClient : remoteClient, true, network);
211
+ },
212
+ benchmarkFn: () => {
213
+ perfCompressor.decompress(finalIdToDecompress);
214
+ },
215
+ });
216
+ });
217
+ let localIdToDecompress;
218
+ benchmark({
219
+ type,
220
+ title: `decompress a local ID into a stable ID`,
221
+ before: () => {
222
+ const network = setupCompressors(initialClusterCapacity, true, true);
223
+ localIdToDecompress = getIdMadeBy(localClient, false, network);
224
+ },
225
+ benchmarkFn: () => {
226
+ perfCompressor.decompress(localIdToDecompress);
227
+ },
228
+ });
229
+ benchmarkWithFlag((eagerFinal) => {
230
+ let stableToCompress;
231
+ benchmark({
232
+ type,
233
+ title: `recompress a stable ID to a ${eagerFinal ? "local" : "final"} ID`,
234
+ before: () => {
235
+ const network = setupCompressors(initialClusterCapacity, true, true);
236
+ stableToCompress = perfCompressor.decompress(getIdMadeBy(localClient, eagerFinal, network));
237
+ },
238
+ benchmarkFn: () => {
239
+ perfCompressor.recompress(stableToCompress);
240
+ },
241
+ });
242
+ });
243
+ benchmarkWithFlag((manySessions) => {
244
+ benchmark({
245
+ type,
246
+ title: `serialize an IdCompressor (${manySessions ? "many sessions" : "many clusters"})`,
247
+ before: () => {
248
+ if (manySessions) {
249
+ perfCompressor = buildHugeCompressor(undefined, initialClusterCapacity);
250
+ }
251
+ else {
252
+ setupCompressors(initialClusterCapacity, false, true);
253
+ }
254
+ },
255
+ benchmarkFn: () => {
256
+ perfCompressor.serialize(false);
257
+ },
258
+ });
259
+ });
260
+ benchmarkWithFlag((manySessions) => {
261
+ let serialized;
262
+ const overrideRemoteSessionId = createSessionId();
263
+ benchmark({
264
+ type,
265
+ title: `deserialize an IdCompressor (${manySessions ? "many sessions" : "many clusters"})`,
266
+ before: () => {
267
+ if (manySessions) {
268
+ perfCompressor = buildHugeCompressor(undefined, initialClusterCapacity);
269
+ }
270
+ else {
271
+ setupCompressors(initialClusterCapacity, false, true);
272
+ }
273
+ serialized = perfCompressor.serialize(false);
274
+ },
275
+ benchmarkFn: () => {
276
+ IdCompressor.deserialize(serialized, overrideRemoteSessionId);
277
+ },
278
+ });
279
+ });
280
+ });
281
+ //# sourceMappingURL=idCompressor.perf.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idCompressor.perf.spec.js","sourceRoot":"","sources":["../../src/test/idCompressor.perf.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;AAE7D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAC;AAS5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAwC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,EACN,MAAM,EACN,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,UAAU,GACV,MAAM,gCAAgC,CAAC;AAExC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,MAAM,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AAC,CAAC,YAAY,EAAE,EAAE;QAClC,SAAS,CAAC;YACT,IAAI;YACJ,KAAK,EAAE,8BACN,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAClC,GAAG;YACH,MAAM,EAAE,GAAG,EAAE;gBACZ,IAAI,YAAY,EAAE;oBACjB,cAAc,GAAG,mBAAmB,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;iBACxE;qBAAM;oBACN,gBAAgB,CAAC,sBAAsB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;iBACtD;YACF,CAAC;YACD,WAAW,EAAE,GAAG,EAAE;gBACjB,cAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,iBAAiB,CAAC,CAAC,YAAY,EAAE,EAAE;QAClC,IAAI,UAAgD,CAAC;QACrD,MAAM,uBAAuB,GAAG,eAAe,EAAE,CAAC;QAClD,SAAS,CAAC;YACT,IAAI;YACJ,KAAK,EAAE,gCACN,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAClC,GAAG;YACH,MAAM,EAAE,GAAG,EAAE;gBACZ,IAAI,YAAY,EAAE;oBACjB,cAAc,GAAG,mBAAmB,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;iBACxE;qBAAM;oBACN,gBAAgB,CAAC,sBAAsB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;iBACtD;gBACD,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAC9C,CAAC;YACD,WAAW,EAAE,GAAG,EAAE;gBACjB,YAAY,CAAC,WAAW,CAAC,UAAU,EAAE,uBAAuB,CAAC,CAAC;YAC/D,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { benchmark, BenchmarkType } from \"@fluid-tools/benchmark\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { take } from \"@fluid-private/stochastic-test-utils\";\nimport {\n\tIdCreationRange,\n\tSerializedIdCompressorWithNoSession,\n\tOpSpaceCompressedId,\n\tSessionSpaceCompressedId,\n\tSessionId,\n\tStableId,\n} from \"..//index.js\";\nimport { IdCompressor } from \"../idCompressor.js\";\nimport { createSessionId } from \"../utilities.js\";\nimport { FinalCompressedId, LocalCompressedId, isFinalId, isLocalId, fail } from \"./testCommon.js\";\nimport {\n\tClient,\n\tDestinationClient,\n\tIdCompressorTestNetwork,\n\tbuildHugeCompressor,\n\tmakeOpGenerator,\n\tperformFuzzActions,\n\tsessionIds,\n} from \"./idCompressorTestUtilities.js\";\n\nconst initialClusterCapacity = 512;\n\ndescribe(\"IdCompressor Perf\", () => {\n\tconst type = BenchmarkType.Measurement;\n\tconst localClient = Client.Client1;\n\tconst remoteClient = Client.Client2;\n\tlet perfCompressor: IdCompressor;\n\n\tfunction setupCompressors(\n\t\tclusterSize: number,\n\t\tlocalClientCanEdit: boolean,\n\t\tsynchronizeAtEnd: boolean,\n\t): IdCompressorTestNetwork {\n\t\tconst perfNetwork = new IdCompressorTestNetwork(clusterSize);\n\t\tconst maxClusterSize = clusterSize * 2;\n\t\tconst generator = take(\n\t\t\t1000,\n\t\t\tmakeOpGenerator({\n\t\t\t\tvalidateInterval: 2000,\n\t\t\t\tmaxClusterSize,\n\t\t\t\toutsideAllocationFraction: 0.9,\n\t\t\t}),\n\t\t);\n\t\tperformFuzzActions(\n\t\t\tgenerator,\n\t\t\tperfNetwork,\n\t\t\tMath.E,\n\t\t\tlocalClientCanEdit ? undefined : localClient,\n\t\t\tsynchronizeAtEnd,\n\t\t);\n\t\tperfCompressor = perfNetwork.getCompressorUnsafeNoProxy(localClient);\n\t\treturn perfNetwork;\n\t}\n\n\tfunction getIdMadeBy(\n\t\tclient: Client,\n\t\teagerFinal: false,\n\t\tnetwork: IdCompressorTestNetwork,\n\t): LocalCompressedId;\n\tfunction getIdMadeBy(\n\t\tclient: Client,\n\t\teagerFinal: true,\n\t\tnetwork: IdCompressorTestNetwork,\n\t): FinalCompressedId & SessionSpaceCompressedId;\n\tfunction getIdMadeBy(\n\t\tclient: Client,\n\t\teagerFinal: boolean,\n\t\tnetwork: IdCompressorTestNetwork,\n\t): SessionSpaceCompressedId;\n\tfunction getIdMadeBy(\n\t\tclient: Client,\n\t\teagerFinal: boolean,\n\t\tnetwork: IdCompressorTestNetwork,\n\t): SessionSpaceCompressedId {\n\t\tconst log = network.getIdLog(client);\n\t\tfor (let i = log.length - 1; i > 0; i--) {\n\t\t\tconst { id, originatingClient } = log[i];\n\t\t\tif (originatingClient === client) {\n\t\t\t\tif ((eagerFinal && isFinalId(id)) || (!eagerFinal && isLocalId(id))) {\n\t\t\t\t\tassert(eagerFinal === isFinalId(id), \"Not local/final as requested.\");\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfail(\"no ID found in log\");\n\t}\n\n\tfunction benchmarkWithFlag(creator: (flag: boolean) => void) {\n\t\tfor (const flag of [true, false]) {\n\t\t\tcreator(flag);\n\t\t}\n\t}\n\n\tbenchmark({\n\t\ttype,\n\t\ttitle: `allocate local ID`,\n\t\tbefore: () => {\n\t\t\tsetupCompressors(initialClusterCapacity, true, true);\n\t\t},\n\t\tbenchmarkFn: () => {\n\t\t\tperfCompressor!.generateCompressedId();\n\t\t},\n\t});\n\n\tbenchmark({\n\t\ttype,\n\t\ttitle: \"take an ID creation range\",\n\t\tbefore: () => {\n\t\t\tsetupCompressors(initialClusterCapacity, true, true);\n\t\t},\n\t\tbenchmarkFn: () => {\n\t\t\tperfCompressor!.generateCompressedId();\n\t\t\tperfCompressor!.takeNextCreationRange();\n\t\t},\n\t});\n\n\tfor (const clusterSize of [1, 10, 500, 1000]) {\n\t\tconst numIds = 7;\n\t\tconst session1 = \"8150a099-5302-4672-b5f3-7a4492b59418\" as SessionId;\n\t\tconst session2 = \"f2ded886-92da-4248-967b-eb96ee04cf51\" as SessionId;\n\t\tlet session: SessionId = session1;\n\t\tlet nextFirstFinalizedGenCount1 = 1;\n\t\tlet nextFirstFinalizedGenCount2 = 1;\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `finalize a range of IDs (cluster size = ${clusterSize})`,\n\t\t\tbefore: () => {\n\t\t\t\tsetupCompressors(clusterSize, false, true);\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\t// Create a range with as minimal overhead as possible, as we'd like for this code to not exist\n\t\t\t\t// in the timing loop at all (but benchmark forces us to do so)\n\t\t\t\tconst isFirstClient = session === session1;\n\t\t\t\tconst firstGenCount = isFirstClient\n\t\t\t\t\t? nextFirstFinalizedGenCount1\n\t\t\t\t\t: nextFirstFinalizedGenCount2;\n\t\t\t\tconst range: IdCreationRange = {\n\t\t\t\t\tsessionId: session,\n\t\t\t\t\tids: {\n\t\t\t\t\t\tfirstGenCount,\n\t\t\t\t\t\tcount: numIds,\n\t\t\t\t\t\trequestedClusterSize: initialClusterCapacity,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tperfCompressor!.finalizeCreationRange(range);\n\n\t\t\t\tconst lastGenCount = firstGenCount + numIds;\n\t\t\t\tif (isFirstClient) {\n\t\t\t\t\tnextFirstFinalizedGenCount1 = lastGenCount;\n\t\t\t\t} else {\n\t\t\t\t\tnextFirstFinalizedGenCount2 = lastGenCount;\n\t\t\t\t}\n\t\t\t\t// Alternate clients to sidestep optimization that packs them all into last cluster\n\t\t\t\tsession = isFirstClient ? session1 : session2;\n\t\t\t},\n\t\t});\n\t}\n\n\tbenchmarkWithFlag((isLocal) => {\n\t\tconst remoteSessionId = sessionIds.get(remoteClient);\n\t\tlet opSpaceId!: OpSpaceCompressedId;\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `normalize a ${\n\t\t\t\tisLocal ? \"local\" : \"final\"\n\t\t\t} ID from a remote session to session space`,\n\t\t\tbefore: () => {\n\t\t\t\tconst network = setupCompressors(initialClusterCapacity, true, true);\n\t\t\t\tconst remoteSession = getIdMadeBy(remoteClient, false, network);\n\t\t\t\topSpaceId = (\n\t\t\t\t\tisLocal\n\t\t\t\t\t\t? remoteSession\n\t\t\t\t\t\t: network.getCompressor(remoteClient).normalizeToOpSpace(remoteSession)\n\t\t\t\t) as OpSpaceCompressedId;\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tperfCompressor!.normalizeToSessionSpace(opSpaceId, remoteSessionId);\n\t\t\t},\n\t\t});\n\t});\n\n\tbenchmarkWithFlag((eagerFinal) => {\n\t\tlet id!: OpSpaceCompressedId & FinalCompressedId;\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `normalize a final ID corresponding to a ${\n\t\t\t\teagerFinal ? \"eager final\" : \"local\"\n\t\t\t} ID from op space to the local session`,\n\t\t\tbefore: () => {\n\t\t\t\tconst network = setupCompressors(initialClusterCapacity, true, true);\n\t\t\t\tconst opId = perfCompressor.normalizeToOpSpace(\n\t\t\t\t\tgetIdMadeBy(localClient, eagerFinal, network),\n\t\t\t\t);\n\t\t\t\tassert(isFinalId(opId), \"Must be final\");\n\t\t\t\tid = opId;\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tperfCompressor!.normalizeToSessionSpace(id, perfCompressor.localSessionId);\n\t\t\t},\n\t\t});\n\t});\n\n\tbenchmarkWithFlag((isLocalOriginator) => {\n\t\tconst remoteSessionId = sessionIds.get(remoteClient);\n\t\tlet opSpaceId!: OpSpaceCompressedId;\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `normalize a final ID from a ${\n\t\t\t\tisLocalOriginator ? \"local\" : \"remote\"\n\t\t\t} session to a small session space (common case)`,\n\t\t\tbefore: () => {\n\t\t\t\tconst network = setupCompressors(initialClusterCapacity, false, true);\n\t\t\t\t// Ensure the local session has several different clusters\n\t\t\t\tfor (let clusterCount = 0; clusterCount < 5; clusterCount++) {\n\t\t\t\t\tnetwork.allocateAndSendIds(\n\t\t\t\t\t\tlocalClient,\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\t\t\t\t\t\tperfCompressor[\"nextRequestedClusterSize\"],\n\t\t\t\t\t);\n\t\t\t\t\tnetwork.allocateAndSendIds(\n\t\t\t\t\t\tremoteClient,\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\t\t\t\t\t\tperfCompressor[\"nextRequestedClusterSize\"] * 2,\n\t\t\t\t\t);\n\t\t\t\t\tnetwork.deliverOperations(DestinationClient.All);\n\t\t\t\t}\n\t\t\t\tconst client = isLocalOriginator ? localClient : remoteClient;\n\t\t\t\tconst idFromSession = getIdMadeBy(client, true, network);\n\t\t\t\topSpaceId = network.getCompressor(client).normalizeToOpSpace(idFromSession);\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tperfCompressor!.normalizeToSessionSpace(opSpaceId, remoteSessionId);\n\t\t\t},\n\t\t});\n\t});\n\n\tlet unackedLocalId!: LocalCompressedId;\n\tbenchmark({\n\t\ttype,\n\t\ttitle: `normalize an unacked local ID from the local session to op space`,\n\t\tbefore: () => {\n\t\t\tconst network = setupCompressors(initialClusterCapacity, true, false);\n\t\t\t// Ensure no eager finals\n\t\t\tnetwork.allocateAndSendIds(\n\t\t\t\tlocalClient,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\t\t\t\tnetwork.getCompressor(localClient)[\"nextRequestedClusterSize\"] * 2 + 1,\n\t\t\t);\n\t\t\tunackedLocalId = getIdMadeBy(localClient, false, network);\n\t\t\tassert(\n\t\t\t\tperfCompressor.normalizeToOpSpace(unackedLocalId) === (unackedLocalId as number),\n\t\t\t\t\"Local was acked.\",\n\t\t\t);\n\t\t},\n\t\tbenchmarkFn: () => {\n\t\t\tperfCompressor!.normalizeToOpSpace(unackedLocalId);\n\t\t},\n\t});\n\n\tbenchmarkWithFlag((eagerFinal) => {\n\t\tlet id!: SessionSpaceCompressedId;\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `normalize an acked ${\n\t\t\t\teagerFinal ? \"eager final\" : \"local\"\n\t\t\t} ID from the local session to op space`,\n\t\t\tbefore: () => {\n\t\t\t\tconst network = setupCompressors(initialClusterCapacity, true, true);\n\t\t\t\tid = getIdMadeBy(localClient, eagerFinal, network);\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tperfCompressor!.normalizeToOpSpace(id);\n\t\t\t},\n\t\t});\n\t});\n\n\tbenchmarkWithFlag((local) => {\n\t\tlet finalIdToDecompress!: SessionSpaceCompressedId & FinalCompressedId;\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `decompress a final ID from a ${\n\t\t\t\tlocal ? \"local\" : \"remote\"\n\t\t\t} client into a stable ID`,\n\t\t\tbefore: () => {\n\t\t\t\tconst network = setupCompressors(initialClusterCapacity, true, true);\n\t\t\t\tfinalIdToDecompress = getIdMadeBy(\n\t\t\t\t\tlocal ? localClient : remoteClient,\n\t\t\t\t\ttrue,\n\t\t\t\t\tnetwork,\n\t\t\t\t);\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tperfCompressor!.decompress(finalIdToDecompress);\n\t\t\t},\n\t\t});\n\t});\n\n\tlet localIdToDecompress!: LocalCompressedId;\n\tbenchmark({\n\t\ttype,\n\t\ttitle: `decompress a local ID into a stable ID`,\n\t\tbefore: () => {\n\t\t\tconst network = setupCompressors(initialClusterCapacity, true, true);\n\t\t\tlocalIdToDecompress = getIdMadeBy(localClient, false, network);\n\t\t},\n\t\tbenchmarkFn: () => {\n\t\t\tperfCompressor!.decompress(localIdToDecompress);\n\t\t},\n\t});\n\n\tbenchmarkWithFlag((eagerFinal) => {\n\t\tlet stableToCompress!: StableId;\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `recompress a stable ID to a ${eagerFinal ? \"local\" : \"final\"} ID`,\n\t\t\tbefore: () => {\n\t\t\t\tconst network = setupCompressors(initialClusterCapacity, true, true);\n\t\t\t\tstableToCompress = perfCompressor.decompress(\n\t\t\t\t\tgetIdMadeBy(localClient, eagerFinal, network),\n\t\t\t\t);\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tperfCompressor!.recompress(stableToCompress);\n\t\t\t},\n\t\t});\n\t});\n\n\tbenchmarkWithFlag((manySessions) => {\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `serialize an IdCompressor (${\n\t\t\t\tmanySessions ? \"many sessions\" : \"many clusters\"\n\t\t\t})`,\n\t\t\tbefore: () => {\n\t\t\t\tif (manySessions) {\n\t\t\t\t\tperfCompressor = buildHugeCompressor(undefined, initialClusterCapacity);\n\t\t\t\t} else {\n\t\t\t\t\tsetupCompressors(initialClusterCapacity, false, true);\n\t\t\t\t}\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tperfCompressor!.serialize(false);\n\t\t\t},\n\t\t});\n\t});\n\n\tbenchmarkWithFlag((manySessions) => {\n\t\tlet serialized!: SerializedIdCompressorWithNoSession;\n\t\tconst overrideRemoteSessionId = createSessionId();\n\t\tbenchmark({\n\t\t\ttype,\n\t\t\ttitle: `deserialize an IdCompressor (${\n\t\t\t\tmanySessions ? \"many sessions\" : \"many clusters\"\n\t\t\t})`,\n\t\t\tbefore: () => {\n\t\t\t\tif (manySessions) {\n\t\t\t\t\tperfCompressor = buildHugeCompressor(undefined, initialClusterCapacity);\n\t\t\t\t} else {\n\t\t\t\t\tsetupCompressors(initialClusterCapacity, false, true);\n\t\t\t\t}\n\t\t\t\tserialized = perfCompressor.serialize(false);\n\t\t\t},\n\t\t\tbenchmarkFn: () => {\n\t\t\t\tIdCompressor.deserialize(serialized, overrideRemoteSessionId);\n\t\t\t},\n\t\t});\n\t});\n});\n"]}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=idCompressor.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idCompressor.spec.d.ts","sourceRoot":"","sources":["../../src/test/idCompressor.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}