@atlaspack/core 2.16.1-canary.2 → 2.16.1-canary.4
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.
- package/CHANGELOG.md +17 -0
- package/lib/RequestTracker.js +36 -17
- package/package.json +17 -17
- package/src/RequestTracker.js +53 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaspack/core
|
|
2
2
|
|
|
3
|
+
## 2.16.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#525](https://github.com/atlassian-labs/atlaspack/pull/525) [`cb9da16`](https://github.com/atlassian-labs/atlaspack/commit/cb9da16fb2648e7f53c64df0313f60d5fb8970cc) Thanks [@yamadapc](https://github.com/yamadapc)! - Fix issues with large blob cache writes, run cache writes in a write transaction
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`1a2c14c`](https://github.com/atlassian-labs/atlaspack/commit/1a2c14c3cd4587551cc12e94d0680c8b71ea12bf), [`cb9da16`](https://github.com/atlassian-labs/atlaspack/commit/cb9da16fb2648e7f53c64df0313f60d5fb8970cc)]:
|
|
10
|
+
- @atlaspack/rust@3.2.0
|
|
11
|
+
- @atlaspack/cache@3.1.0
|
|
12
|
+
- @atlaspack/fs@2.14.4
|
|
13
|
+
- @atlaspack/logger@2.14.4
|
|
14
|
+
- @atlaspack/utils@2.14.4
|
|
15
|
+
- @atlaspack/package-manager@2.14.4
|
|
16
|
+
- @atlaspack/workers@2.14.4
|
|
17
|
+
- @atlaspack/types@2.14.4
|
|
18
|
+
- @atlaspack/plugin@2.14.4
|
|
19
|
+
|
|
3
20
|
## 2.16.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/lib/RequestTracker.js
CHANGED
|
@@ -30,6 +30,13 @@ function _buildCache() {
|
|
|
30
30
|
};
|
|
31
31
|
return data;
|
|
32
32
|
}
|
|
33
|
+
function _cache() {
|
|
34
|
+
const data = require("@atlaspack/cache");
|
|
35
|
+
_cache = function () {
|
|
36
|
+
return data;
|
|
37
|
+
};
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
33
40
|
function _featureFlags() {
|
|
34
41
|
const data = require("@atlaspack/feature-flags");
|
|
35
42
|
_featureFlags = function () {
|
|
@@ -45,7 +52,7 @@ function _graph() {
|
|
|
45
52
|
return data;
|
|
46
53
|
}
|
|
47
54
|
function _logger() {
|
|
48
|
-
const data =
|
|
55
|
+
const data = _interopRequireWildcard(require("@atlaspack/logger"));
|
|
49
56
|
_logger = function () {
|
|
50
57
|
return data;
|
|
51
58
|
};
|
|
@@ -926,6 +933,20 @@ class RequestTracker {
|
|
|
926
933
|
};
|
|
927
934
|
}
|
|
928
935
|
async writeToCache(signal) {
|
|
936
|
+
const options = this.options;
|
|
937
|
+
async function runCacheImprovements(newPath, oldPath) {
|
|
938
|
+
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
939
|
+
(0, _assert().default)(options.cache instanceof _cache().LMDBLiteCache);
|
|
940
|
+
const result = await newPath(options.cache);
|
|
941
|
+
return result;
|
|
942
|
+
} else {
|
|
943
|
+
const result = await oldPath();
|
|
944
|
+
return result;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
await runCacheImprovements(async cache => {
|
|
948
|
+
await cache.getNativeRef().startWriteTransaction();
|
|
949
|
+
}, () => Promise.resolve());
|
|
929
950
|
let cacheKey = getCacheKey(this.options);
|
|
930
951
|
let requestGraphKey = `requestGraph-${cacheKey}`;
|
|
931
952
|
if (this.options.shouldDisableCache) {
|
|
@@ -939,21 +960,23 @@ class RequestTracker {
|
|
|
939
960
|
size: this.graph.nodes.length
|
|
940
961
|
});
|
|
941
962
|
let serialisedGraph = this.graph.serialize();
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
}
|
|
963
|
+
|
|
964
|
+
// Delete an existing request graph cache, to prevent invalid states
|
|
965
|
+
await this.options.cache.deleteLargeBlob(requestGraphKey);
|
|
946
966
|
const serialiseAndSet = async (key, contents) => {
|
|
947
967
|
if (signal !== null && signal !== void 0 && signal.aborted) {
|
|
948
968
|
throw new Error('Serialization was aborted');
|
|
949
969
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
970
|
+
await runCacheImprovements(cache => {
|
|
971
|
+
(0, _logger().instrument)(`cache.put(${key})`, () => {
|
|
972
|
+
cache.getNativeRef().putNoConfirm(key, (0, _buildCache().serialize)(contents));
|
|
973
|
+
});
|
|
974
|
+
return Promise.resolve();
|
|
975
|
+
}, async () => {
|
|
953
976
|
await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
|
|
954
977
|
signal: signal
|
|
955
978
|
} : undefined);
|
|
956
|
-
}
|
|
979
|
+
});
|
|
957
980
|
total += 1;
|
|
958
981
|
(0, _ReporterRunner.report)({
|
|
959
982
|
type: 'cache',
|
|
@@ -1014,6 +1037,9 @@ class RequestTracker {
|
|
|
1014
1037
|
// If we have aborted, ignore the error and continue
|
|
1015
1038
|
if (!(signal !== null && signal !== void 0 && signal.aborted)) throw err;
|
|
1016
1039
|
}
|
|
1040
|
+
await runCacheImprovements(async cache => {
|
|
1041
|
+
await cache.getNativeRef().commitWriteTransaction();
|
|
1042
|
+
}, () => Promise.resolve());
|
|
1017
1043
|
(0, _ReporterRunner.report)({
|
|
1018
1044
|
type: 'cache',
|
|
1019
1045
|
phase: 'end',
|
|
@@ -1057,13 +1083,6 @@ function getRequestGraphNodeKey(index, cacheKey) {
|
|
|
1057
1083
|
}
|
|
1058
1084
|
async function readAndDeserializeRequestGraph(cache, requestGraphKey, cacheKey) {
|
|
1059
1085
|
let bufferLength = 0;
|
|
1060
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
1061
|
-
let data = (0, _nullthrows().default)(await cache.get(requestGraphKey));
|
|
1062
|
-
return {
|
|
1063
|
-
requestGraph: RequestGraph.deserialize(data),
|
|
1064
|
-
bufferLength
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
1086
|
const getAndDeserialize = async key => {
|
|
1068
1087
|
let buffer = await cache.getLargeBlob(key);
|
|
1069
1088
|
bufferLength += Buffer.byteLength(buffer);
|
|
@@ -1101,7 +1120,7 @@ async function loadRequestGraph(options) {
|
|
|
1101
1120
|
snapshotKey
|
|
1102
1121
|
}
|
|
1103
1122
|
});
|
|
1104
|
-
if (
|
|
1123
|
+
if (await options.cache.hasLargeBlob(requestGraphKey)) {
|
|
1105
1124
|
try {
|
|
1106
1125
|
let {
|
|
1107
1126
|
requestGraph
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/core",
|
|
3
|
-
"version": "2.16.1-canary.
|
|
3
|
+
"version": "2.16.1-canary.4+9dee30885",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,21 +20,21 @@
|
|
|
20
20
|
"check-ts": "tsc --noEmit index.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@atlaspack/build-cache": "2.13.3-canary.
|
|
24
|
-
"@atlaspack/cache": "3.0.2-canary.
|
|
25
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
26
|
-
"@atlaspack/events": "2.14.1-canary.
|
|
27
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
28
|
-
"@atlaspack/fs": "2.14.4-canary.
|
|
29
|
-
"@atlaspack/graph": "3.4.1-canary.
|
|
30
|
-
"@atlaspack/logger": "2.14.4-canary.
|
|
31
|
-
"@atlaspack/package-manager": "2.14.4-canary.
|
|
32
|
-
"@atlaspack/plugin": "2.14.4-canary.
|
|
33
|
-
"@atlaspack/profiler": "2.14.1-canary.
|
|
34
|
-
"@atlaspack/rust": "3.1.2-canary.
|
|
35
|
-
"@atlaspack/types": "2.14.4-canary.
|
|
36
|
-
"@atlaspack/utils": "2.14.4-canary.
|
|
37
|
-
"@atlaspack/workers": "2.14.4-canary.
|
|
23
|
+
"@atlaspack/build-cache": "2.13.3-canary.67+9dee30885",
|
|
24
|
+
"@atlaspack/cache": "3.0.2-canary.4+9dee30885",
|
|
25
|
+
"@atlaspack/diagnostic": "2.14.1-canary.67+9dee30885",
|
|
26
|
+
"@atlaspack/events": "2.14.1-canary.67+9dee30885",
|
|
27
|
+
"@atlaspack/feature-flags": "2.14.1-canary.67+9dee30885",
|
|
28
|
+
"@atlaspack/fs": "2.14.4-canary.4+9dee30885",
|
|
29
|
+
"@atlaspack/graph": "3.4.1-canary.67+9dee30885",
|
|
30
|
+
"@atlaspack/logger": "2.14.4-canary.4+9dee30885",
|
|
31
|
+
"@atlaspack/package-manager": "2.14.4-canary.4+9dee30885",
|
|
32
|
+
"@atlaspack/plugin": "2.14.4-canary.4+9dee30885",
|
|
33
|
+
"@atlaspack/profiler": "2.14.1-canary.67+9dee30885",
|
|
34
|
+
"@atlaspack/rust": "3.1.2-canary.4+9dee30885",
|
|
35
|
+
"@atlaspack/types": "2.14.4-canary.4+9dee30885",
|
|
36
|
+
"@atlaspack/utils": "2.14.4-canary.4+9dee30885",
|
|
37
|
+
"@atlaspack/workers": "2.14.4-canary.4+9dee30885",
|
|
38
38
|
"@mischnic/json-sourcemap": "^0.1.0",
|
|
39
39
|
"@parcel/source-map": "^2.1.1",
|
|
40
40
|
"base-x": "^3.0.8",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"./src/serializerCore.js": "./src/serializerCore.browser.js"
|
|
68
68
|
},
|
|
69
69
|
"type": "commonjs",
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "9dee30885fc8c0f3654d54151d75f1e89907dafd"
|
|
71
71
|
}
|
package/src/RequestTracker.js
CHANGED
|
@@ -4,7 +4,7 @@ import invariant, {AssertionError} from 'assert';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
6
|
import {deserialize, serialize} from '@atlaspack/build-cache';
|
|
7
|
-
import type
|
|
7
|
+
import {LMDBLiteCache, type Cache} from '@atlaspack/cache';
|
|
8
8
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
9
9
|
import {ContentGraph} from '@atlaspack/graph';
|
|
10
10
|
import type {
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
SerializedContentGraph,
|
|
15
15
|
Graph,
|
|
16
16
|
} from '@atlaspack/graph';
|
|
17
|
-
import logger from '@atlaspack/logger';
|
|
17
|
+
import logger, {instrument} from '@atlaspack/logger';
|
|
18
18
|
import {hashString} from '@atlaspack/rust';
|
|
19
19
|
import type {Async, EnvMap} from '@atlaspack/types';
|
|
20
20
|
import {
|
|
@@ -1457,6 +1457,28 @@ export default class RequestTracker {
|
|
|
1457
1457
|
}
|
|
1458
1458
|
|
|
1459
1459
|
async writeToCache(signal?: AbortSignal) {
|
|
1460
|
+
const options = this.options;
|
|
1461
|
+
async function runCacheImprovements<T>(
|
|
1462
|
+
newPath: (cache: LMDBLiteCache) => Promise<T>,
|
|
1463
|
+
oldPath: () => Promise<T>,
|
|
1464
|
+
): Promise<T> {
|
|
1465
|
+
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
1466
|
+
invariant(options.cache instanceof LMDBLiteCache);
|
|
1467
|
+
const result = await newPath(options.cache);
|
|
1468
|
+
return result;
|
|
1469
|
+
} else {
|
|
1470
|
+
const result = await oldPath();
|
|
1471
|
+
return result;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
await runCacheImprovements(
|
|
1476
|
+
async (cache) => {
|
|
1477
|
+
await cache.getNativeRef().startWriteTransaction();
|
|
1478
|
+
},
|
|
1479
|
+
() => Promise.resolve(),
|
|
1480
|
+
);
|
|
1481
|
+
|
|
1460
1482
|
let cacheKey = getCacheKey(this.options);
|
|
1461
1483
|
let requestGraphKey = `requestGraph-${cacheKey}`;
|
|
1462
1484
|
let snapshotKey = `snapshot-${cacheKey}`;
|
|
@@ -1475,10 +1497,8 @@ export default class RequestTracker {
|
|
|
1475
1497
|
|
|
1476
1498
|
let serialisedGraph = this.graph.serialize();
|
|
1477
1499
|
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
await this.options.cache.deleteLargeBlob(requestGraphKey);
|
|
1481
|
-
}
|
|
1500
|
+
// Delete an existing request graph cache, to prevent invalid states
|
|
1501
|
+
await this.options.cache.deleteLargeBlob(requestGraphKey);
|
|
1482
1502
|
|
|
1483
1503
|
const serialiseAndSet = async (
|
|
1484
1504
|
key: string,
|
|
@@ -1489,19 +1509,25 @@ export default class RequestTracker {
|
|
|
1489
1509
|
throw new Error('Serialization was aborted');
|
|
1490
1510
|
}
|
|
1491
1511
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1512
|
+
await runCacheImprovements(
|
|
1513
|
+
(cache) => {
|
|
1514
|
+
instrument(`cache.put(${key})`, () => {
|
|
1515
|
+
cache.getNativeRef().putNoConfirm(key, serialize(contents));
|
|
1516
|
+
});
|
|
1517
|
+
return Promise.resolve();
|
|
1518
|
+
},
|
|
1519
|
+
async () => {
|
|
1520
|
+
await this.options.cache.setLargeBlob(
|
|
1521
|
+
key,
|
|
1522
|
+
serialize(contents),
|
|
1523
|
+
signal
|
|
1524
|
+
? {
|
|
1525
|
+
signal: signal,
|
|
1526
|
+
}
|
|
1527
|
+
: undefined,
|
|
1528
|
+
);
|
|
1529
|
+
},
|
|
1530
|
+
);
|
|
1505
1531
|
|
|
1506
1532
|
total += 1;
|
|
1507
1533
|
|
|
@@ -1592,6 +1618,13 @@ export default class RequestTracker {
|
|
|
1592
1618
|
if (!signal?.aborted) throw err;
|
|
1593
1619
|
}
|
|
1594
1620
|
|
|
1621
|
+
await runCacheImprovements(
|
|
1622
|
+
async (cache) => {
|
|
1623
|
+
await cache.getNativeRef().commitWriteTransaction();
|
|
1624
|
+
},
|
|
1625
|
+
() => Promise.resolve(),
|
|
1626
|
+
);
|
|
1627
|
+
|
|
1595
1628
|
report({type: 'cache', phase: 'end', total, size: this.graph.nodes.length});
|
|
1596
1629
|
}
|
|
1597
1630
|
|
|
@@ -1641,14 +1674,6 @@ export async function readAndDeserializeRequestGraph(
|
|
|
1641
1674
|
): Async<{|requestGraph: RequestGraph, bufferLength: number|}> {
|
|
1642
1675
|
let bufferLength = 0;
|
|
1643
1676
|
|
|
1644
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
1645
|
-
let data = nullthrows(await cache.get(requestGraphKey));
|
|
1646
|
-
return {
|
|
1647
|
-
requestGraph: RequestGraph.deserialize(data),
|
|
1648
|
-
bufferLength,
|
|
1649
|
-
};
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1652
1677
|
const getAndDeserialize = async (key: string) => {
|
|
1653
1678
|
let buffer = await cache.getLargeBlob(key);
|
|
1654
1679
|
bufferLength += Buffer.byteLength(buffer);
|
|
@@ -1699,10 +1724,7 @@ async function loadRequestGraph(options): Async<RequestGraph> {
|
|
|
1699
1724
|
},
|
|
1700
1725
|
});
|
|
1701
1726
|
|
|
1702
|
-
if (
|
|
1703
|
-
!getFeatureFlag('cachePerformanceImprovements') &&
|
|
1704
|
-
(await options.cache.hasLargeBlob(requestGraphKey))
|
|
1705
|
-
) {
|
|
1727
|
+
if (await options.cache.hasLargeBlob(requestGraphKey)) {
|
|
1706
1728
|
try {
|
|
1707
1729
|
let {requestGraph} = await readAndDeserializeRequestGraph(
|
|
1708
1730
|
options.cache,
|