Page MenuHomePhabricator

Review front-end performance of convertTableToJson usage
Closed, ResolvedPublicBUG REPORT

Description

Description

zobjectUtils.js convertTableToJson has quite a lot of complexity, and it's used extensively. Particularly:

  • Every time we need to get the type of an object by rowId, we call convertTableToJson (for the sub-zobject): this is called many times
  • When we use function call widget, we convert the metadata to table, and then convert back to Json: this is called once but it's an unnecessary step

We should audit the usage of this and limit it to the minimum
Additionally, we should improve the performance of the convertTableToJson so that it's not so costly on the UI

Root cause

Why are these methods so costly?

Building a JSON representation of the flattened zobject table representation is costly when the object is very large.

I can identify two main reasons:

  1. Row ids are different to the index that the row takes in the array.
    • As a result, getRowById requires walking all the table, row by row, searching for an id match.
    • getRowById is a nuclear operation performed again and again
  1. Children rows point at their parent, but there's no reverse index
    • As a result, getChildrenByParentRowId requires walking all the table, row by row, searching for all the id=parent matches
    • getChildrenByParentRowId is a nuclear operation performed again and again

Ideas:

Test cases

(added 2025-01-23, by @DMartin-WMF )
The UI performance can be stress-tested by fetching sizable Wikidata items (as described below). For example, two large Wikidata items, which the UI currently is unacceptably slow in presenting, are Q144 / dog and Q64 / Berlin. I have seen both of these display successfully, after several minutes of waiting and telling Chrome to continue waiting. But more often, after some waiting, Chrome shows me an Out of Memory message.

To observe a quick, acceptable response time, try fetching a small item such as Q302556 / Catholic Encyclopedia. Q42 / Douglas Adams is a moderately large item, which usually shows up quickly for me in collapsed form, but after clicking the chevron can cause the browser to run out of memory.

Here are rough indications of the sizes of the 3 problematic items (by number of labels) and typical reported orchestrator processing times. In addition to the labels, these items have many descriptions, aliases, and statements.

  • Q42 / Douglas Adams
    • approx. 69 labels
    • Orchestrator duration: 4134 ms
  • Q144 / dog
    • approx. 300 labels
    • Orchestrator duration: 6483 ms
  • Q64 / Berlin
    • approx. 270 labels
    • Orchestrator duration: 7017 ms

To fetch and attempt to display a Wikidata item:

  • Visit Z6821
  • In Try this function / Enter inputs, type in the Q-ID (e.g. "Q42")
  • When you see the item title (e.g., "Douglas Adams"), click on it
  • Then click Run function

Completion checklist

Event Timeline

Change #1083205 had a related patch set uploaded (by Genoveva Galarza; author: Genoveva Galarza):

[mediawiki/extensions/WikiLambda@master] [WIP] explore getZObjectTypeByRowId performance improvements

https://gerrit.wikimedia.org/r/1083205

Change #1085375 had a related patch set uploaded (by Genoveva Galarza; author: Genoveva Galarza):

[mediawiki/extensions/WikiLambda@master] Skip metadata two-way transformation

https://gerrit.wikimedia.org/r/1085375

Change #1083205 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] Avoid unnecessary calls to getZObjectAsJsonById in getZObjectTypeByRowId

https://gerrit.wikimedia.org/r/1083205

Change #1085375 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] Skip metadata two-way transformation

https://gerrit.wikimedia.org/r/1085375

Change #1087204 had a related patch set uploaded (by Genoveva Galarza; author: Genoveva Galarza):

[mediawiki/extensions/WikiLambda@master] Fix edge case when typeToString is called with undefined

https://gerrit.wikimedia.org/r/1087204

Change #1087204 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] Fix edge case when typeToString is called with undefined

https://gerrit.wikimedia.org/r/1087204

gengh changed the task status from Open to In Progress.Mar 4 2025, 2:54 PM
gengh updated the task description. (Show Details)