stumptown-content
stumptown-content copied to clipboard
There's something very inefficient about link lists in build-json
The function itemFromDirectory
is called, as of today, 21 times. For each directory. In total, that function gets called 1,630 times when it should be 1,630/21 times.
Perhaps @wbamberg can see the whole picture better but I'd rather not memoize this function but take a step back and be aware of calling it instead. The itemFromDirectory
is actually a "private" (not exported) function that is used by the exported functions linkListFromChapterList
, linkListFromDirectory
, and linkListFromFilePaths
I think.
So those functions might be better aware of what it's calling.
But perhaps it goes deeper than that. Actually, I think linkListFromChapterList
is called 21 times with /content/learn/html/Introduction_to_HTML.yaml
and 21 times with /content/html/guides/Guides.yaml
.
So, perhaps one needs to zoom out even further and eventually do something like this:
+ const list = {};
stuff.forEach(thing => {
- const relatedLinks = doSomething(thing.directory);
+ if (!list[thing.directory]) {
+ list[thing.directory] = doSomething(thing.directory);
+ }
+ const relatedLinks = list[thing.directory]
Note, this is not urgent because npm run build-json
only takes about 3-4 seconds. But that'll potentially be exponentially worse when the number of files increases.
Yes, build-json is very inefficient, and when (not if) it becomes enough of a problem we should rewrite it, in particular (I expect) to minimise the number of file reads we do.