Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
perf(core/xref): reuse obj when adding query id (speced#3727)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Aug 3, 2021
1 parent 1a772be commit e85a95e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
8 changes: 6 additions & 2 deletions src/core/xref.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export async function run(conf) {
const queryKeys = [];
for (const elem of elems) {
const entry = getRequestEntry(elem);
const id = await objectHash(entry);
queryKeys.push({ ...entry, id });
entry.id = await objectHash(entry);
queryKeys.push(entry);
}

const data = await getData(queryKeys, xref.url);
Expand Down Expand Up @@ -172,6 +172,10 @@ function getRequestEntry(elem) {
const forContext = getForContext(elem, isIDL);

return {
// Add an empty `id` to ensure the shape of object returned stays same when
// actual `id` is added later (minor perf optimization, also makes
// TypeScript happy).
id: "",
term,
types,
...(specs.length && { specs }),
Expand Down
40 changes: 20 additions & 20 deletions tests/data/xref/refs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"result": [
[
"964a6928f0061e8a28c6e799dc1777a1bababe74",
"ab7db5bcda5172f65990774c08b2d5623d0ca4d9",
[
{
"shortname": "local-1",
Expand All @@ -12,7 +12,7 @@
]
],
[
"ab349a2eac4671070c40c1c1763bf973ff856fa6",
"cb3348a71fc96423a724d214e32b0a6f6d19f270",
[
{
"shortname": "infra",
Expand All @@ -23,7 +23,7 @@
]
],
[
"ace10a8db6b758d2d2523077211fea575daa6ac4",
"8ab59f6080eccb6cd1cb43884d30467b294761dd",
[
{
"shortname": "css-values",
Expand All @@ -34,7 +34,7 @@
]
],
[
"b3f39e21ff440b3efd5949b8952c0f23f11b23a2",
"a99184f1d06a2664d14b22732d462985ba9993a1",
[
{
"shortname": "url",
Expand All @@ -45,7 +45,7 @@
]
],
[
"ea07a98420b98807471b6041b15b612b6590fc52",
"98f59682aab42126e30db05b4fc748fb891654b1",
[
{
"shortname": "local-2",
Expand All @@ -56,7 +56,7 @@
]
],
[
"c7ef0091ed0c25312798d467d3d1aa1fdc9368cc",
"2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071",
[
{
"shortname": "html",
Expand All @@ -67,7 +67,7 @@
]
],
[
"1cb8c55085c55d02477232bc3910ad4a1fa72183",
"ea274f5f7e4d9bd49503932f92e96377bcc6d32c",
[
{
"shortname": "local-3",
Expand All @@ -78,7 +78,7 @@
]
],
[
"7a82727efd37620ec8b50cac9dca75d1b1f08d94",
"3f57765140cc67750fba716a57c6acd2897aac33",
[
{
"shortname": "webidl",
Expand All @@ -89,7 +89,7 @@
]
],
[
"ac3f5f63e6a2ed0b384e5284f09abdfbe826b17e",
"2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b",
[
{
"shortname": "local-4",
Expand All @@ -100,7 +100,7 @@
]
],
[
"8b2f8e4c2e57922a662f9be57e4183c25038dcaf",
"4ef7705f121b9b2228672ec56b8d3a4f491a0c20",
[
{
"shortname": "infra",
Expand All @@ -115,52 +115,52 @@
{
"term": "fake inform 1",
"types": ["_CONCEPT_"],
"id": "964a6928f0061e8a28c6e799dc1777a1bababe74"
"id": "ab7db5bcda5172f65990774c08b2d5623d0ca4d9"
},
{
"term": "list",
"types": ["_CONCEPT_"],
"id": "ab349a2eac4671070c40c1c1763bf973ff856fa6"
"id": "cb3348a71fc96423a724d214e32b0a6f6d19f270"
},
{
"term": "bearing angle",
"types": ["_CONCEPT_"],
"id": "ace10a8db6b758d2d2523077211fea575daa6ac4"
"id": "8ab59f6080eccb6cd1cb43884d30467b294761dd"
},
{
"term": "url parser",
"types": ["_CONCEPT_"],
"id": "b3f39e21ff440b3efd5949b8952c0f23f11b23a2"
"id": "a99184f1d06a2664d14b22732d462985ba9993a1"
},
{
"term": "fake inform 2",
"types": ["_CONCEPT_"],
"id": "ea07a98420b98807471b6041b15b612b6590fc52"
"id": "98f59682aab42126e30db05b4fc748fb891654b1"
},
{
"term": "event handler",
"types": ["_CONCEPT_"],
"id": "c7ef0091ed0c25312798d467d3d1aa1fdc9368cc"
"id": "2ae12bb4ce51410e6b99a24e4bf8f1d664fe0071"
},
{
"term": "fake inform 3",
"types": ["_CONCEPT_"],
"id": "1cb8c55085c55d02477232bc3910ad4a1fa72183"
"id": "ea274f5f7e4d9bd49503932f92e96377bcc6d32c"
},
{
"term": "dictionary",
"types": ["_CONCEPT_"],
"id": "7a82727efd37620ec8b50cac9dca75d1b1f08d94"
"id": "3f57765140cc67750fba716a57c6acd2897aac33"
},
{
"term": "fake inform 4",
"types": ["_CONCEPT_"],
"id": "ac3f5f63e6a2ed0b384e5284f09abdfbe826b17e"
"id": "2d0e5d79ca098268a8a4fa1a432b49b18c4fce8b"
},
{
"term": "ascii alphanumeric",
"types": ["_CONCEPT_"],
"id": "8b2f8e4c2e57922a662f9be57e4183c25038dcaf"
"id": "4ef7705f121b9b2228672ec56b8d3a4f491a0c20"
}
]
}

0 comments on commit e85a95e

Please sign in to comment.