Skip to content

perf: network optimizations#108

Open
orangishcat wants to merge 37 commits intoaehmttw:masterfrom
orangishcat:network-optimization-cleaned
Open

perf: network optimizations#108
orangishcat wants to merge 37 commits intoaehmttw:masterfrom
orangishcat:network-optimization-cleaned

Conversation

@orangishcat
Copy link
Copy Markdown
Contributor

deletes half the codebase

  • Reflection handler to populate event fields without additional code
  • Trimmed all doubles to floats and some ints to shorts
  • Changed Game.networkRate from 60 to 20
  • Overall, reduced network traffic (upstream/downstream) by around 80%

Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
@orangishcat
Copy link
Copy Markdown
Contributor Author

Marking as draft as there are still strange interpolation issues i need to fix (will do tmrw)

Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
@orangishcat orangishcat marked this pull request as ready for review September 14, 2025 06:44
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
@orangishcat
Copy link
Copy Markdown
Contributor Author

Additional changes and stuff to test:

  • Explosions now destroy properly on client side, don't emit duplicate destroy events (thanks furret)
  • Stackable events are placed in linked hash maps to preserve stacked event order
  • Applied continuous shooting to bullets with less than 10 cooldown
  • Made bullet shoot and bullet destroy events stackable for bullets with zero cooldown
  • Added EventSetItemCount to replace EventSetItem when only the count of the item has changed
  • Made a bunch more events stackable to reduce network load
  • Added Game.recordEventData "Record event data" debug option to record network KB/s of each event every second
  • Quick actions is now sent through the network encoded as an int (thanks F6)
  • Fixed EventTankUpdateHealth to display the correct health value at all times
  • Added validation upon game launch of network events to ensure every read call is paired with a write call
  • Extracted duplicate functionality in ServerHandler and ClientHandler into NetworkHandler
  • Probably more that I forgot about

Also double check interpolation so that the tank id 0 tank isn't stuck in the corner or anything

@orangishcat orangishcat changed the title feat: network optimizations perf: network optimizations Sep 15, 2025
# Conflicts:
#	src/main/java/tanks/Game.java
#	src/main/java/tanks/hotbar/ItemBar.java
#	src/main/java/tanks/network/event/EventSetItemCount.java
#	src/main/java/tanks/network/event/EventTankUpdateHealth.java
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
Comment thread src/main/java/tanks/Game.java Outdated
Comment thread src/main/java/tanks/bullet/Bullet.java Outdated
@aehmttw
Copy link
Copy Markdown
Owner

aehmttw commented Dec 1, 2025

Screen Shot 2025-12-01 at 2 23 11 AM (2) the tank health is not consistent

Signed-off-by: orangishcat <fdsnail2@gmail.com>
Signed-off-by: orangishcat <fdsnail2@gmail.com>
# Conflicts:
#	src/main/java/tanks/Game.java
Signed-off-by: orangishcat <fdsnail2@gmail.com>
# Conflicts:
#	src/main/java/tanks/hotbar/ItemBar.java
#	src/main/java/tanks/network/event/EventAddNPCShopItem.java
#	src/main/java/tanks/network/event/EventAddShopItem.java
#	src/main/java/tanks/network/event/EventSortShopButtons.java
Signed-off-by: orangishcat <fdsnail2@gmail.com>
# Conflicts:
#	src/main/java/tanks/network/event/EventExplosion.java
Copy link
Copy Markdown
Collaborator

@ghostlypi ghostlypi left a comment

Choose a reason for hiding this comment

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

I've flagged a few changes which are purely syntactic and unecessary for the function of the pull request. Some of these issues will be addressed when the branch is linted, however it is important to note that it's annoying to have to review this because first, syntactic and technical changes need to be separated before any evaluation as to the correctness of optimizations can be done.

Additionally the issue with FastUtil is that it does not work on iOS. I think it's worth not using until FastUtil can be made to work on iOS.

if (this.effect == Operation.add)
return in + val;
else if (this.effect == Operation.multiply)
if (this.effect == Operation.multiply)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not really an optimization. I think it's more of a syntactic difference than anything else.

Comment thread src/main/java/tanks/bullet/Bullet.java Outdated
for (ArrayList<Trail> trail : this.trails)
{
if (trail.size() > 0)
if (!trail.isEmpty())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is another syntactic difference, not a performance optimization.

if (this.usable(t) && !this.destroy)
{
use(t);
use(t);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is going on here?

import io.netty.buffer.ByteBuf;
import tanks.Drawing;
import tanks.Game;
import tanks.*;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A lot of this stuff has been fixed by linting so I recommend you rebase. It should also help keep the code everyone writes consistent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, these are notatbly not optimizations.

}
}
}
package tanks.network.event;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A change like this is annoying to review because the whole file is marked as a diff. Actually seeing the diff for things like this is not fun.

public boolean action1;
public boolean action2;
public boolean[] quickActions = new boolean[TankPlayer.max_abilities];
public int tank, quickActions;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I really am not a fan of putting imports on the same line. It's better to keep them separated than put them all together. Also this is a syntactic change, not an optimization.

@orangishcat
Copy link
Copy Markdown
Contributor Author

Fastutil is not essential, most of the changes work without it.

@ghostlypi
Copy link
Copy Markdown
Collaborator

Can you re-base, lint, and reformat to make this easier to merge?

@orangishcat
Copy link
Copy Markdown
Contributor Author

Yeah I need to fix all the merge conflicts first

# Conflicts:
#	src/main/java/tanks/AreaEffectFreeze.java
#	src/main/java/tanks/Chunk.java
#	src/main/java/tanks/DebugKeybinds.java
#	src/main/java/tanks/Game.java
#	src/main/java/tanks/Level.java
#	src/main/java/tanks/ModAPI.java
#	src/main/java/tanks/Panel.java
#	src/main/java/tanks/attribute/AttributeModifier.java
#	src/main/java/tanks/bullet/Bullet.java
#	src/main/java/tanks/bullet/BulletAirStrike.java
#	src/main/java/tanks/bullet/BulletInstant.java
#	src/main/java/tanks/bullet/BulletReboundIndicator.java
#	src/main/java/tanks/gui/screen/ScreenDebug.java
#	src/main/java/tanks/item/Item.java
#	src/main/java/tanks/network/Client.java
#	src/main/java/tanks/network/ClientHandler.java
#	src/main/java/tanks/network/MessageReader.java
#	src/main/java/tanks/network/NetworkEventMap.java
#	src/main/java/tanks/network/NetworkUtils.java
#	src/main/java/tanks/network/Server.java
#	src/main/java/tanks/network/ServerHandler.java
#	src/main/java/tanks/network/event/EventAddColoredTile.java
#	src/main/java/tanks/network/event/EventAddFixedShape.java
#	src/main/java/tanks/network/event/EventAddNPC.java
#	src/main/java/tanks/network/event/EventAddObstacle.java
#	src/main/java/tanks/network/event/EventAddObstacleBullet.java
#	src/main/java/tanks/network/event/EventAddObstacleText.java
#	src/main/java/tanks/network/event/EventAddScoreboard.java
#	src/main/java/tanks/network/event/EventAirdropTank.java
#	src/main/java/tanks/network/event/EventAnnounceConnection.java
#	src/main/java/tanks/network/event/EventArcadeClearMovables.java
#	src/main/java/tanks/network/event/EventArcadeFrenzy.java
#	src/main/java/tanks/network/event/EventBeginLevelCountdown.java
#	src/main/java/tanks/network/event/EventBulletBounce.java
#	src/main/java/tanks/network/event/EventBulletDestroyed.java
#	src/main/java/tanks/network/event/EventBulletInstantWaypoint.java
#	src/main/java/tanks/network/event/EventBulletReboundIndicator.java
#	src/main/java/tanks/network/event/EventBulletStunEffect.java
#	src/main/java/tanks/network/event/EventBulletUpdateTarget.java
#	src/main/java/tanks/network/event/EventChangeBackgroundColor.java
#	src/main/java/tanks/network/event/EventChangeScoreboardAttribute.java
#	src/main/java/tanks/network/event/EventChat.java
#	src/main/java/tanks/network/event/EventClearNPCShop.java
#	src/main/java/tanks/network/event/EventClearShop.java
#	src/main/java/tanks/network/event/EventConnectionSuccess.java
#	src/main/java/tanks/network/event/EventCreateFreezeEffect.java
#	src/main/java/tanks/network/event/EventDisplayText.java
#	src/main/java/tanks/network/event/EventDisplayTextGroup.java
#	src/main/java/tanks/network/event/EventEnterLevel.java
#	src/main/java/tanks/network/event/EventItemDrop.java
#	src/main/java/tanks/network/event/EventItemPickup.java
#	src/main/java/tanks/network/event/EventKick.java
#	src/main/java/tanks/network/event/EventLayMine.java
#	src/main/java/tanks/network/event/EventLevelExit.java
#	src/main/java/tanks/network/event/EventLevelFinished.java
#	src/main/java/tanks/network/event/EventLoadItemBarSlot.java
#	src/main/java/tanks/network/event/EventLoadLevel.java
#	src/main/java/tanks/network/event/EventMutePlayer.java
#	src/main/java/tanks/network/event/EventNudge.java
#	src/main/java/tanks/network/event/EventObstacleBoostPanelEffect.java
#	src/main/java/tanks/network/event/EventObstacleDestroy.java
#	src/main/java/tanks/network/event/EventObstacleShrubberyBurn.java
#	src/main/java/tanks/network/event/EventPing.java
#	src/main/java/tanks/network/event/EventPlayerAutoReady.java
#	src/main/java/tanks/network/event/EventPlayerAutoReadyConfirm.java
#	src/main/java/tanks/network/event/EventPlayerChat.java
#	src/main/java/tanks/network/event/EventPlayerReady.java
#	src/main/java/tanks/network/event/EventPlayerRevealBuild.java
#	src/main/java/tanks/network/event/EventPlayerSetBuild.java
#	src/main/java/tanks/network/event/EventPurchaseBuild.java
#	src/main/java/tanks/network/event/EventPurchaseNPCItem.java
#	src/main/java/tanks/network/event/EventReturnToCrusade.java
#	src/main/java/tanks/network/event/EventReturnToLobby.java
#	src/main/java/tanks/network/event/EventScoreboardUpdateScore.java
#	src/main/java/tanks/network/event/EventSendClientDetails.java
#	src/main/java/tanks/network/event/EventSendTankColors.java
#	src/main/java/tanks/network/event/EventSetItem.java
#	src/main/java/tanks/network/event/EventSetItemBarSlot.java
#	src/main/java/tanks/network/event/EventSetItemCount.java
#	src/main/java/tanks/network/event/EventSetupHotbar.java
#	src/main/java/tanks/network/event/EventShareCrusade.java
#	src/main/java/tanks/network/event/EventShareLevel.java
#	src/main/java/tanks/network/event/EventShootBullet.java
#	src/main/java/tanks/network/event/EventShowCrusadeStats.java
#	src/main/java/tanks/network/event/EventSortNPCShopButtons.java
#	src/main/java/tanks/network/event/EventTankAddAttributeModifier.java
#	src/main/java/tanks/network/event/EventTankCharge.java
#	src/main/java/tanks/network/event/EventTankControllerUpdateC.java
#	src/main/java/tanks/network/event/EventTankControllerUpdateS.java
#	src/main/java/tanks/network/event/EventTankCreate.java
#	src/main/java/tanks/network/event/EventTankCustomCreate.java
#	src/main/java/tanks/network/event/EventTankMimicLaser.java
#	src/main/java/tanks/network/event/EventTankMimicTransform.java
#	src/main/java/tanks/network/event/EventTankPlayerCreate.java
#	src/main/java/tanks/network/event/EventTankSpawn.java
#	src/main/java/tanks/network/event/EventTankTeleport.java
#	src/main/java/tanks/network/event/EventTankTransformCustom.java
#	src/main/java/tanks/network/event/EventTankTransformPreset.java
#	src/main/java/tanks/network/event/EventTankUpdate.java
#	src/main/java/tanks/network/event/EventTankUpdateColor.java
#	src/main/java/tanks/network/event/EventTankUpdateHealth.java
#	src/main/java/tanks/network/event/EventTankUpdateVisibility.java
#	src/main/java/tanks/network/event/EventUpdateCoins.java
#	src/main/java/tanks/network/event/EventUpdateEliminatedPlayers.java
#	src/main/java/tanks/network/event/EventUpdateReadyPlayers.java
#	src/main/java/tanks/network/event/EventUpdateRemainingLives.java
#	src/main/java/tanks/network/event/EventUpdateTankAbility.java
#	src/main/java/tanks/network/event/INetworkEvent.java
#	src/main/java/tanks/network/event/IStackableEvent.java
#	src/main/java/tanks/network/event/PersonalEvent.java
#	src/main/java/tanks/network/event/online/EventAddButton.java
#	src/main/java/tanks/network/event/online/EventAddMenuButton.java
#	src/main/java/tanks/network/event/online/EventAddShape.java
#	src/main/java/tanks/network/event/online/EventAddText.java
#	src/main/java/tanks/network/event/online/EventAddTextBox.java
#	src/main/java/tanks/network/event/online/EventAddUUIDTextBox.java
#	src/main/java/tanks/network/event/online/EventSendLevelToDownload.java
#	src/main/java/tanks/network/event/online/EventSendOnlineClientDetails.java
#	src/main/java/tanks/network/event/online/EventSetPauseScreenTitle.java
#	src/main/java/tanks/network/event/online/EventUploadLevel.java
#	src/main/java/tanks/obstacle/Obstacle.java
#	src/main/java/tanks/tank/Mine.java
#	src/main/java/tanks/tank/Tank.java
#	src/main/java/tanks/tank/TankPlayerRemote.java
#	src/main/java/tanks/tank/TankRemote.java
Signed-off-by: orangishcat <fdsnail2@gmail.com>
@orangishcat orangishcat force-pushed the network-optimization-cleaned branch from 4bc4a9a to 15c9203 Compare March 29, 2026 06:17
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.

3 participants