Page MenuHomePhabricator

Optimizing data encapsulation in mw.loadData() for enhanced efficiency
Closed, DuplicatePublic

Description

Description:

  • mw.loadData(), although it caches the data page-wide, still calls dataWrapper() every time to encapsulate the data.

Code references:

Use case:

  • Module A, designed to be lightweight, requires module B to utilize some of its helper methods. Module A uses nothing else from module B.
  • Module B, which is significantly heavier, calls mw.loadData() during initialization.
  • Most of module B uses the loaded data, except for a few helper methods, which are the only methods that module A utilizes.
  • Module B is typically used elsewhere on the page, ensuring the data is always required somewhere on the page. Thus, eager loading the data is acceptable.

Problem:

  • If Module A is invoked 1000 times during a page rendering, the data is loaded once by either the first call of Module A or Module B. However, dataWrapper() is called 1000 times needlessly, these redundant calls should be avoided.

Proposed solution:

  • To enhance efficiency, cache the encapsulated data (the result of dataWrapper()), instead of the raw data. Since the table is read-only, there shouldn't be any potential issues with this approach.

Mention:

  • Ping Theknightwho who has shown interest in similar topics.

Event Timeline

Sorry, I had forgotten about that ticket T148313 (from 2016!).

However, I just replied on that old ticket: the issue might actually be reopened. (Edit: upon further review, it appears nothing can be done to improve the situation.)