-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preload data when using Dex.mod #10641
Conversation
With the initial introduction fo TypeScript at 3716f36, ``Dex.mod``, and ``Dex.format`` (nowadays ``Dex.forFormat``) no longer ensured that the data cache has been filled. Newer lazy-loading getter APIs were introduced, which were intended to be used as a replacement for direct access to the loaded data (``dataCache``). However, these APIs were either not effective or not properly used., as reflected by 43ef4d9, which reverted ``Dex.forFormat`` to its full capabilities. Nevertheless, ``Dex.mod`` was left untouched, which results in a footgun where ``Dex.forFormat('gen1randbats').gen == 1``, but ``Dex.mod('gen1').gen == 9``. This commit brings back ``Dex.mod`` to its original behavior, so that gen information is always there when it's needed.
In theory, assuming But it's pointless to do that, since that would effectively add |
Well, there's the code path where you query |
Maybe one of PS downstream dependant projects could make use of it. I would support adding that default value, for completeness. But it departs a bit from the purpose of this PR. Do you say I should add it here? |
I see what you mean about scope creep; I now agree that a separate PR would be better; for instance it would presumably allow the removal of the |
This is more reliable given the load order.
🤔 I was originally taking your statement as (roughly) suggesting to (1) add
(3) A default value for |
I feel like (2) is the ideal solution. But only if we are done migrating subprocesses to using |
I think the root of the problem is the eager loading of mods but lazy loading of data in IMO the best solution in the long run is to both
1 requires axing Dex.dexes() and Dex.includeMods() - they have contracts that cannot be implemented both efficiently and correctly. 2 is literally just simpler code. And it makes object de-duplication easier / viable. There's still plenty of pointless memory in dex, so if lower memory usage was the motivation behind lazy loading, code changes are necessary to achieve that anyway. We don't need to expose fake data because the real data just isn't that expensive when done right! |
To better justify my point, here's code that bypasses
Granted, we could just move them to |
There is a chronological inaccuracy here. Lazy loading predates the existence of all the So things that have changed since then is that there are now many more independent libraries that PS includes. What I mentioned earlier: we are done migrating subprocesses to using Utils instead of Dex for all their non-Pokémon related needs is a required condition to retire lazy loading. However, ideally also the main process shouldn't need loading unneeded
Dex.mod should indeed be the one used by chat plugins (*). I mean, APIs exist for a reason. Dex.dexes are simply internals. Among those lines you listed, there are 2 comment lines (lol), and 3 lines that don't help your case whatsoever. The other lines are from the same chat plugin. Unfortunately, nobody seriously reviews nor cares much about correctness of plugins. So I don't think it's fair to use these as an argument. Regarding plugins and mods sloppiness, linter rules forbidding many bad patterns, such as direct edition of data without (*) This is according to the assumption that the |
Those mods would already have to be changed from |
I'm sure it made sense at the time. But as the problem changes, the code needs to catch up.
If you want some data but not other data, then just separate them? Getting a list of names shouldn't require constructing the objects, lazy-loaded internals or not. I know I come off as very critical, I just think dex could be much simpler without sacrificing perf. A hierarchy of tables shouldn't be so confusing! |
I'd like to keep the lazy loading, and very trivially be able to disable caching to keep my RAM as low as ever. Is that wishful thinking? If it's not, may I add that I would also like PS to start up in 3 seconds, instead of 5+ minutes?
I'm not volunteering. Also, I don't mind the critiques. In fact, I am preemptively providing my own critiques for when you enthusiastically PR those improvements 😃 |
As of PR smogon#10641, these are no longer necessary.
As of PR #10641, these are no longer necessary.
With the initial introduction fo TypeScript at 3716f36,
Dex.mod
, andDex.format
(nowadaysDex.forFormat
) no longer ensured that the data cache has been filled.Newer lazy-loading getter APIs were introduced, which were intended to be used as a replacement for direct access to the loaded data (
dataCache
).However, these APIs were either not effective or not properly used., as reflected by 43ef4d9, which reverted
Dex.forFormat
to its full capabilities.Nevertheless,
Dex.mod
was left untouched, which results in a footgun whereDex.forFormat('gen1randbats').gen == 1
, butDex.mod('gen1').gen == 9
- when ran from different processes.This commit brings back
Dex.mod
to its original behavior, so that gen information is always there when it's needed.Thanks to @larry-the-table-guy for reporting this issue.