Skip to content

Commit

Permalink
Store graph edges in SharedArrayBuffer (#6922)
Browse files Browse the repository at this point in the history
  • Loading branch information
lettertwo committed Nov 16, 2021
1 parent 145bfb8 commit cacdf67
Show file tree
Hide file tree
Showing 13 changed files with 1,672 additions and 229 deletions.
17 changes: 14 additions & 3 deletions packages/core/core/src/AssetGraph.js
@@ -1,7 +1,12 @@
// @flow strict-local

import type {GraphVisitor} from '@parcel/types';
import type {ContentKey, NodeId, SerializedContentGraph} from '@parcel/graph';
import type {
ContentGraphOpts,
ContentKey,
NodeId,
SerializedContentGraph,
} from '@parcel/graph';
import type {
Asset,
AssetGraphNode,
Expand Down Expand Up @@ -31,6 +36,12 @@ type InitOpts = {|
assetGroups?: Array<AssetGroup>,
|};

type AssetGraphOpts = {|
...ContentGraphOpts<AssetGraphNode>,
symbolPropagationRan: boolean,
hash?: ?string,
|};

type SerializedAssetGraph = {|
...SerializedContentGraph<AssetGraphNode>,
hash?: ?string,
Expand Down Expand Up @@ -104,7 +115,7 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
envCache: Map<string, Environment>;
symbolPropagationRan: boolean;

constructor(opts: ?SerializedAssetGraph) {
constructor(opts: ?AssetGraphOpts) {
if (opts) {
let {hash, symbolPropagationRan, ...rest} = opts;
super(rest);
Expand All @@ -125,7 +136,7 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
}

// $FlowFixMe[prop-missing]
static deserialize(opts: SerializedAssetGraph): AssetGraph {
static deserialize(opts: AssetGraphOpts): AssetGraph {
return new AssetGraph(opts);
}

Expand Down
22 changes: 16 additions & 6 deletions packages/core/core/src/BundleGraph.js
Expand Up @@ -6,7 +6,11 @@ import type {
Symbol,
TraversalActions,
} from '@parcel/types';
import type {NodeId, SerializedContentGraph} from '@parcel/graph';
import type {
ContentGraphOpts,
NodeId,
SerializedContentGraph,
} from '@parcel/graph';

import type {
Asset,
Expand Down Expand Up @@ -73,6 +77,14 @@ type InternalExportSymbolResolution = {|
+exportAs: Symbol | string,
|};

type BundleGraphOpts = {|
graph: ContentGraphOpts<BundleGraphNode, BundleGraphEdgeType>,
bundleContentHashes: Map<string, string>,
assetPublicIds: Set<string>,
publicIdByAssetId: Map<string, string>,
symbolPropagationRan: boolean,
|};

type SerializedBundleGraph = {|
$$raw: true,
graph: SerializedContentGraph<BundleGraphNode, BundleGraphEdgeType>,
Expand Down Expand Up @@ -174,7 +186,7 @@ export default class BundleGraph {
let fromIds;
if (assetGroupIds.has(edge.from)) {
fromIds = [
...assetGraph.inboundEdges.getEdges(
...assetGraph.getNodeIdsConnectedTo(
edge.from,
bundleGraphEdgeTypes.null,
),
Expand All @@ -185,7 +197,7 @@ export default class BundleGraph {

for (let from of fromIds) {
if (assetGroupIds.has(edge.to)) {
for (let to of assetGraph.outboundEdges.getEdges(
for (let to of assetGraph.getNodeIdsConnectedFrom(
edge.to,
bundleGraphEdgeTypes.null,
)) {
Expand Down Expand Up @@ -223,7 +235,7 @@ export default class BundleGraph {
};
}

static deserialize(serialized: SerializedBundleGraph): BundleGraph {
static deserialize(serialized: BundleGraphOpts): BundleGraph {
return new BundleGraph({
graph: ContentGraph.deserialize(serialized.graph),
assetPublicIds: serialized.assetPublicIds,
Expand Down Expand Up @@ -1031,7 +1043,6 @@ export default class BundleGraph {
},
visit,
undefined, // start with root
// $FlowFixMe
ALL_EDGE_TYPES,
);
}
Expand Down Expand Up @@ -1221,7 +1232,6 @@ export default class BundleGraph {
return this._graph
.getNodeIdsConnectedTo(
this._graph.getNodeIdByContentKey(asset.id),
// $FlowFixMe
ALL_EDGE_TYPES,
)
.map(id => nullthrows(this._graph.getNode(id)))
Expand Down
20 changes: 18 additions & 2 deletions packages/core/core/src/RequestTracker.js
Expand Up @@ -4,7 +4,12 @@ import type {AbortSignal} from 'abortcontroller-polyfill/dist/cjs-ponyfill';
import type {Async, EnvMap} from '@parcel/types';
import type {EventType, Options as WatcherOptions} from '@parcel/watcher';
import type WorkerFarm from '@parcel/workers';
import type {ContentKey, NodeId, SerializedContentGraph} from '@parcel/graph';
import type {
ContentGraphOpts,
ContentKey,
NodeId,
SerializedContentGraph,
} from '@parcel/graph';
import type {
ParcelOptions,
RequestInvalidation,
Expand Down Expand Up @@ -55,6 +60,17 @@ export const requestGraphEdgeTypes = {
};

export type RequestGraphEdgeType = $Values<typeof requestGraphEdgeTypes>;

type RequestGraphOpts = {|
...ContentGraphOpts<RequestGraphNode, RequestGraphEdgeType>,
invalidNodeIds: Set<NodeId>,
incompleteNodeIds: Set<NodeId>,
globNodeIds: Set<NodeId>,
envNodeIds: Set<NodeId>,
optionNodeIds: Set<NodeId>,
unpredicatableNodeIds: Set<NodeId>,
|};

type SerializedRequestGraph = {|
...SerializedContentGraph<RequestGraphNode, RequestGraphEdgeType>,
invalidNodeIds: Set<NodeId>,
Expand Down Expand Up @@ -201,7 +217,7 @@ export class RequestGraph extends ContentGraph<
unpredicatableNodeIds: Set<NodeId> = new Set();

// $FlowFixMe[prop-missing]
static deserialize(opts: SerializedRequestGraph): RequestGraph {
static deserialize(opts: RequestGraphOpts): RequestGraph {
// $FlowFixMe[prop-missing]
let deserialized = new RequestGraph(opts);
deserialized.invalidNodeIds = opts.invalidNodeIds;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/test/AssetGraph.test.js
Expand Up @@ -150,7 +150,7 @@ describe('AssetGraph', () => {
}).id,
),
);
assert.deepEqual(graph.getAllEdges(), [
assert.deepEqual(Array.from(graph.getAllEdges()), [
{
from: graph.rootNodeId,
to: graph.getNodeIdByContentKey('entry_specifier:path/to/index1'),
Expand Down

0 comments on commit cacdf67

Please sign in to comment.