Skip to content

Commit

Permalink
Avoid using JSON.stringify([...]) in makeDepKey helper function.
Browse files Browse the repository at this point in the history
Creating a throwaway array just to call JSON.stringify was much more
expensive than string concatenation. The exact format of these cache keys
is an invisible implementation detail, so I picked something that seemed
unlikely ever to be ambiguous, though we can easily change it later.
  • Loading branch information
benjamn committed Feb 15, 2020
1 parent 0c6ee74 commit 1b8208e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cache/inmemory/entityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ class CacheGroup {
}

function makeDepKey(dataId: string, storeFieldName: string) {
return JSON.stringify([dataId, fieldNameFromStoreName(storeFieldName)]);
// Since field names cannot have newline characters in them, this method
// of joining the field name and the ID should be unambiguous, and much
// cheaper than JSON.stringify([dataId, fieldName]).
return fieldNameFromStoreName(storeFieldName) + "\n" + dataId;
}

export namespace EntityStore {
Expand Down

0 comments on commit 1b8208e

Please sign in to comment.