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

Spark performance improvements #4459

Merged
merged 11 commits into from
Oct 15, 2023

Conversation

anonymous123-code
Copy link
Contributor

Fixes #4389

Sparks already had a lot of the infrastructure needed, but I basically changed spark from recalculating everything every tick to being notified when stuff changes. Note that this approach is more prone to bugs, especially when more funcitonality gets added. The issue also goes a lot more into detail. I also tested using Fabric's block cache API but it didn't turn out to be worth it.

Setup profiled:
(Screenshot TBD)
10 Minutes superflat, no mob spawning, no daylight cycle (In dev)

Runtime of: vazkii.botania.common.entity.ManaSparkEntity.tick()
With mana running:

Fabric Forge
Before (ms) 37,269 92,968
After (ms) 19,736 46,217
After/Before 52% 49%

When empty:

Fabric Forge
Before (ms) 24,147 50,048
After (ms) 3,821 9,726
After/Before 15% 19%

I already tested a lot of stuff before rebasing (But that one was like 1.19.2), so I'll need to retest.
Tested:

  • Fabric
    • Singleplayer
    • Server
  • Fabric
    • Singleplayer
    • Server

@williewillus
Copy link
Member

Very nice, could you go through and add inline comments explaining what's being done at a high level? I think that would help review.

Like for example, I see the state/BE params being removed from findManaReceiver, which I'm assuming is to boost perf, but would be nice to have that called out instead of me assuming.

@anonymous123-code
Copy link
Contributor Author

anonymous123-code commented Oct 8, 2023

Actually I think that one was a leftover from me implementing caching. I can change it, although that pattern might be common enough that its better to just keep it...
I'll comment the other stuff tho

@anonymous123-code
Copy link
Contributor Author

Stuff should be better now, I left the findManaReceiver refactorings in as that method already existed before the PR.

Copy link
Member

@williewillus williewillus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, some more questions and we should land this for the next beta

transfersTowardsSelfToRegister.add(spark);
}
}
Collections.shuffle(transfersTowardsSelfToRegister);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reasoning for the shuffles that were added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise mana pools would be loaded in a relatively consistent order, making only some fill up. This makes it so if they're reloaded, that order is shuffled at least sometimes. A similar thing was in here before, I'm only guessing the reason why it has been implemented: https://github.com/VazkiiMods/Botania/pull/4459/files#diff-6ab7cbbb33c3d206fc8ca670958f924a1353804a7fb8f234f3308622d23723f7L172
I can also add the transfers directly, but that would be slightly breaking with older behavior (Previosly, and in this implementation dominant sparks would only add one transfer each tick, taking some time to initialize). This would make transfersTowardsSelfToRegister unnecessary.

}

@Override
public boolean areIncomingTransfersDone() {
if (getAttachedManaReceiver() instanceof ManaPool) {
return removeTransferants > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I'm not really sure what this old code did lol, do you know and can you explain why it should be removed?

Copy link
Contributor Author

@anonymous123-code anonymous123-code Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemoveTransferants was the old reset logic when stuff like the upgrade or the network changed. This is now handled differently. And the only reason why it might be removed is if it is full, which is checked seperately, so I changed it to be a constant false

Better names
Remove at end, to save copying performance
Avoid potential memory leak when dominant is switched in and out quickly
@williewillus williewillus merged commit 1d37051 into VazkiiMods:1.20.x Oct 15, 2023
1 check passed
@williewillus
Copy link
Member

let's get it tested in the next beta

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

Successfully merging this pull request may close these issues.

Poor spark performance
2 participants