mirror of
https://github.com/status-im/sourcecred.git
synced 2025-01-11 21:24:35 +00:00
Improve performance of pagerank decompose
(#1007)
When I implemented this function, I incorrectly assumed that `lodash.sortBy` only calls subsequent accessor functions if there is a tie from the first accessor. Actually, it calls it every time. We can avoid lots of wasteful JSON.serialization by just grabbing the exact properties of interest. Test plan: For correctness: `yarn test` suffices, as this functionality is already tested. For performance improvement: I ran the full load+analyze workflow, in Chrome, on twbs/bootstrap. Before this change, decompose took 6.9s; after this change, it takes 1.3s, for a 5.3x speedup. Close #943.
This commit is contained in:
parent
80b458d719
commit
794b93e397
@ -44,8 +44,19 @@ export function decompose(
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
(x) => -x.connectionScore,
|
(x) => -x.connectionScore,
|
||||||
// The following should be called rarely and on small objects.
|
(x) => x.connection.adjacency.type,
|
||||||
(x) => JSON.stringify(x.connection.adjacency)
|
(x) => {
|
||||||
|
switch (x.connection.adjacency.type) {
|
||||||
|
case "IN_EDGE":
|
||||||
|
return x.connection.adjacency.edge.address;
|
||||||
|
case "OUT_EDGE":
|
||||||
|
return x.connection.adjacency.edge.address;
|
||||||
|
case "SYNTHETIC_LOOP":
|
||||||
|
return "";
|
||||||
|
default:
|
||||||
|
throw new Error((x.connection.adjacency.type: empty));
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
return {score, scoredConnections};
|
return {score, scoredConnections};
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user