Skip to content
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

Removes map of class to module #5026

Closed
wants to merge 4,075 commits into from

Conversation

PoTheMagicDragon
Copy link

@PoTheMagicDragon PoTheMagicDragon commented Nov 27, 2024

Type of change

  • Bug fix
  • New feature

Description

Makes it so there's a single source of truth for the modules list. I've been running into an issue creating an addon with multiple modules that have the same class created by a generic module builder.

Related issues

N/A

How Has This Been Tested?

Running Meteor and making sure the modules load correctly.

Checklist:

  • My code follows the style guidelines of this project.
  • I have added comments to my code in more complex areas.
  • I have tested the code in both development and production environments.

bruh1273 and others added 30 commits January 6, 2024 18:41
Allows users to disconnect from a server, and specify a `reason` message too.
Marked <0.5.6 as breaking, seeing the mixin changes.
Made it always disable in water because it's impossible to avoid taking hunger while moving in water
@MineGame159
Copy link
Member

I mean you are still filtering the list based on the class, so it has same effect as a map, no?

@PoTheMagicDragon
Copy link
Author

Kind of. For

    public <T extends Module> T get(Class<T> klass) 

absolutely, but all of the other .values() calls, it will have the correct behavior. Currently the .values() only gets one instance of the multiple modules I've added

@MineGame159
Copy link
Member

Ah, well in that case I think it's still good to keep the map purely for the get operation. Searching the list is much slower and retrieving the module is called very frequently.

@PoTheMagicDragon
Copy link
Author

On the surface level that's what it would seem, but it's a micro optimization that in all reality probably makes no difference. Take a look at this for example. https://medium.com/@dejangegic100/why-benchmarks-are-lying-to-you-and-hash-maps-are-not-always-faster-than-arrays-ac42cae649a7

@PoTheMagicDragon
Copy link
Author

That being said, I can keep it for the get by class portion if you'd prefer

@RacoonDog
Copy link
Contributor

RacoonDog commented Dec 14, 2024

On the surface level that's what it would seem, but it's a micro optimization that in all reality probably makes no difference.

your pull request makes the average runtime of Modules#get roughly 73x slower, up to 107x slower if we take into account the two most popular meteor client addons

now consider that Modules#get is used in 334 different places in the meteor client codebase

@RacoonDog
Copy link
Contributor

i'm fairly curious in seeing what your generic module builder looks like though

@PoTheMagicDragon
Copy link
Author

@RacoonDog How did you take those benchmarks?

@PoTheMagicDragon
Copy link
Author

I just did some benchmarking and it looks like you're right. It ran a little faster than 73x (I think it was 50 something) but setting up the stream is more resource intensive than I thought. I swapped it out with a plain ol for loop and it was was significantly better but still 5x slower than using the map. I'll update my pr in a bit

@PoTheMagicDragon
Copy link
Author

Note, I'm closing this branch due to mangled history from trying to fix accidentally leaking private information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.