Commit Graph

2500 Commits

Author SHA1 Message Date
Aikar
55e17a8599
Wait for Async Tasks during shutdown
Server.reload() had this logic to give time for tasks to shutdown,
however shutdown did not...

Adds a 5 second grace period for any async tasks to finish and warns
if any are still running after that delay just as reload does.

Closes #3337
2020-05-10 22:17:55 -04:00
Aikar
b59052566b
Ensure Entity AABB's are never invalid
If anything used setPositionRaw, it left potential for an AABB
to be left stale at their old location, which could cause massive
AABB boxes if movement ever then got called on the new position.

This guarantees any time we set the entities position, we also
update their AABB.
2020-05-10 22:14:47 -04:00
Aikar
a054aa6f02
Properly remove Entities from current chunk
We store a reference to the chunk the entity is currently in, so use it
to more accurately unregister it in chunkCheck

Should maybe fix some entity loss issues.
2020-05-10 05:52:31 -04:00
Aikar
c894ddfd38
Fix teleporting onto a chunk line
Obscure detail in that if you teleport right on a chunk line, it
adds +1 to your collision check and will check the unloaded neighbor.

but the call to load the chunk then returned null if it was pending unload, such
as the load we did in Player List

However we want gen=true for players here anyways, so use getType
2020-05-10 05:52:26 -04:00
Aikar
57d6cc0158
Send LOGIN protocol packets immediately - Fix disconnect during async prelogin 2020-05-10 03:12:05 -04:00
Aikar
cd93e54df3
Don't use our modified chunk checks for collision in world gen
Fixes issues with errors in logs on generating chunks
2020-05-10 02:27:50 -04:00
Aikar
b4003ef1ca
Allow loading entities current chunk if needed to fix collision checks
Having trouble reproducing this myself, but this should do it.
2020-05-10 01:04:45 -04:00
Aikar
e5f6489602
Add Urgent API for Async Chunks API and use it for Async Teleport
This also cleans up the implementation of Async Chunks to get rid of most
Consumer callbacks and instead return futures.

This lets us propogate errors correctly up the future chain
(barring one isn't lost even deeper in the chain...)

So exceptions can now bubble to plugins using getChunkAtAsync
2020-05-10 00:57:03 -04:00
Aikar
ad8e59dc79
Ensure chunks loaded on respawn for suffocation check 2020-05-09 21:13:30 -04:00
Aikar
b1691e7b69
Remove some Streams usage in Entity Collision
While there is more down the collision system, remove some of the wrapping
Spliterator stuff as even this wrapper stream has shown up in profiling.

With other collision optimizations, we might also even avoid inner streams too.
2020-05-09 19:38:31 -04:00
JellySquid
d454bbd5e1
Implement JellySquid's Entity Collision optimisations patch
This patch replaces the vanilla collision code for both block and entity collisions with faster implementations by JellySquid, used originally in her Lithium mod.

Optimizes Full Block voxel collisions, and removes streams from Entity collisions

Original code by JellySquid, licensed under GNU Lesser General Public License v3.0
you can find the original code on https://github.com/jellysquid3/lithium-fabric/tree/1.15.x/fabric (Yarn mappings)

Ported by
Co-authored-by: Zoutelande <54509836+Zoutelande@users.noreply.github.com>

Touched up by Aikar to keep previous paper optimizations
2020-05-09 19:19:18 -04:00
Aikar
8e85f841d8
Optimize Collision to not load chunks
The collision code takes an AABB and generates a cuboid of checks rather
than a cylinder, so at high velocity this can generate a lot of chunk checks.

Treat an unloaded chunk as a collision for entities, and also for players if
the "prevent moving into unloaded chunks" setting is enabled.

If that setting is not enabled, collisions will be ignored for players, since
movement will load only the chunk the player enters anyways and avoids loading
massive amounts of surrounding chunks due to large AABB lookups.

Fixes #3321
2020-05-09 19:19:08 -04:00
Aikar
ceb824dbde
Fix ChunkCache .getXIfLoaded to use the local chunks in the cache
It was calling back out to world for it, we already have them.

Also use the nocache method for building the chunk cache too.
2020-05-09 14:58:08 -04:00
Aikar
f6f9157bd4
Don't toString block unless actually showing the message
This is causing MASSIVE performance issues with hoppers and block states
in general.
2020-05-09 13:55:41 -04:00
Aikar
ec8d7387ad
MC-183249: Don't generate Carving Masks BitSet unless needed
This was using SIGNIFICANT amounts of memory allocating many
long[]'s for BitSets for every ProtoChunk in the cache that had
been unloaded and reloaded.

This will result in a nice memory reduction.
2020-05-09 12:13:29 -04:00
Aikar
2d401d2dfb
Improve BlockPosition hashCode/equals
Actually showed up in profiling as decent time spent here...

Noticed y/z was missing its final that it use to have, when x had it. some how
must of got messed up on some update. though people suggest this shouldn't of
mattered anyways, but lets put it back for safety.

Added cache of hashcode, as well as optimized the hash code using larger primes.
Also stored the long value of the x/y/z so that for equals we can compare a single long,
as well as have that long value cached for .asLong()
2020-05-09 10:59:29 -04:00
Aikar
2572bd017c
Fix world unload toLowercase - Fixes #3326 2020-05-09 10:59:10 -04:00
virustotalop
dda9680be5
Optimize brigadier child sorting performance
Use a TreeMap instead of a LinkedHashMap and then manually sorting

This will significantly reduce CPU usage on logging in and changing worlds.
2020-05-08 20:55:44 -04:00
Aikar
a71a4ec215
Fix CraftServer.unloadWorld Leak
The dimension manager was still registered which leaked the entire World
2020-05-08 20:40:42 -04:00
Aikar
f6fc0d4cd4
Don't create region files for chunk checks - mistake on upstream merge
Accidently handled a conflict wrong in a previous upstream merge and set wrong param.
2020-05-08 18:22:37 -04:00
Aikar
cfed00cf54
Fix Light Command
This lets you run /paper fixlight <chunkRadius> (max 5) to automatically
fix all light data in the chunks.

Permission node is same "bukkit.command.paper"
2020-05-07 19:44:33 -04:00
Aikar
a6ff84add7
Revert Nibble patch, causing issues still 2020-05-07 05:30:40 -04:00
Aikar
f1a8eb7fda
Use a finalizer for light packet instead of onPacketDone
Sadly sharing packets is breaking the ability to do this :(

We can prob still do a little better than this but will save that
for another commit.
2020-05-07 01:58:23 -04:00
Aikar
03c9bb05c1
Optimize NibbleArray to use pooled buffers
Massively reduces memory allocation of 2048 byte buffers by using
an object pool for these.
2020-05-07 01:32:02 -04:00
Aikar
d0a528b1cb
Move delayed init down later in tick, improve accuracy of startup time
Now tracks the full startup time for "Done" message at end, as apparently
Vanillas was done in a place that skipped tracking a lot of code too.

This fixes an issue with ViaVersion
2020-05-06 21:24:43 -04:00
Aikar
cc477e6abb
Force Plugins that use delayed tasks for init back in their place
Will now run those tasks just before we print "Done" so that startup
time is appropriately accounted for a plugin, as well as will no longer
trip the watchdog on startup.

Any plugin that tries to bypass this is just going to then trip watchdog
on Spigot too, so don't you dare.

Stop trying to cheat the delay your plugin added to startup time.

This isn't a behavior change because the first thing the tick does....
was run these tasks....

So it's just moving it slightly a few lines to be before a watchdog tick and
to account for it in "Done" time.

Fixes #3294
2020-05-06 20:18:31 -04:00
Aikar
597263fd55
Don't skip full player connection tick when dead
Still need to send keep alives and kick for idle

Fixes #3299
2020-05-06 19:30:47 -04:00
Spottedleaf
e2c23475b5
Revert loaded entity list (#3304) 2020-05-06 11:31:29 -05:00
Spottedleaf
fa87db6b91
Move another NetworkManager util into the inner class (#3303)
Those poor souls running outdated ProtocolLib.
2020-05-06 10:07:51 -05:00
Spottedleaf
841c7d1879
Make loaded entity list logic more consistent (#3301)
When adding/removing to a chunk, we need to also look at
editing the loaded entity list.

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
2020-05-06 09:57:18 -05:00
Aikar
36f34f01c0
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
da9ef3c5 #496: Add methods to get/set ItemStacks in EquipmentSlots
3abebc9f #492: Let Tameable extend Animals rather than Entity
941111a0 #495: Expose ItemStack and hand used in PlayerShearEntityEvent
4fe19cae #494: InventoryView - Add missing Brewing FUEL_TIME

CraftBukkit Changes:
933e9094 #664: Add methods to get/set ItemStacks in EquipmentSlots
18722312 #662: Expose ItemStack and hand used in PlayerShearEntityEvent
2020-05-06 06:05:22 -04:00
Aikar
5ca5f131bb
Rebuild all patches using the new rebuild pattern 2020-05-06 05:48:49 -04:00
Mariell Hoversholm
1ccff6fabb
Add villager reputation API 2020-05-06 05:48:06 -04:00
Aikar
f37381ea8a
Optimize Network Manager to not need synchronization
Removes synchronization from sending packets
Makes normal packet sends no longer need to be wrapped and queued like it use to work.
Adds more packet queue immunities on top of keep alive to let the following scenarios go out
without delay:
  - Keep Alive
  - Chat
  - Kick
  - All of the packets during the Player Joined World event

Hoping that latter one helps join timeout issues more too for slow connections.

Removes processing packet queue off of main thread
  - for the few cases where it is allowed, order is not necessary nor
    should it even be happening concurrently in first place (handshaking/login/status)

Ensures packets sent asynchronously are dispatched on main thread

This helps ensure safety for ProtocolLib as packet listeners
are commonly accessing world state. This will allow you to schedule
a packet to be sent async, but itll be dispatched sync for packet
listeners to process.

This should solve some deadlock risks

This may provide a decent performance improvement because thread synchronization incurs a cache reset
so by avoiding ever entering a synchronized block, we get to avoid that, and packet sending is a really
hot activity.
2020-05-06 05:28:47 -04:00
stonar96
8f9df2ed43
Anti Xray cleanup
Undo the accidental renaming of a method in 0aad8bf
Aikar wanted to rename DataPalette#getDataBits(T object) to getOrCreateIdFor
in 0aad8bf but he also accidentally renamed
ChunkPacketInfo#getDataBitsIndex(int chunkSectionIndex) to
getOrCreateIdForIndex.

Remove chunk-edge-mode and chunk loading entirely from Anti-Xray
The chunk-edge-mode is broken since several versions.
Loading chunk neighbors for chunk edge obfuscation isn't needed anymore.
Unlike in previous versions, these are under normal circumstances already loaded
at the time we need them (plugins for example can bypass this).

Use the modified methods and constructors everywhere
Anti-Xray provides support for the default nms methods and constructors,
which where modified by Anti-Xray to avoid breaking stuff (plugins)
which somehow uses these methods.
However, the modified versions of those methods and constructors should be used
where possible.
2020-05-06 04:35:20 -04:00
Spottedleaf
878c66f116
No-Tick view distance implementation - Closes #3196
Implements world view distance getters/setters

Per-Player is absent due to difficulty of maintaining
the diff required to make it happen.
2020-05-06 03:50:52 -04:00
Spottedleaf
b87743c1e0
Stop copy-on-write operations for updating light data
Causes huge memory allocations + gc issues
2020-05-06 03:48:56 -04:00
Spottedleaf
97a9c9724a
Optimize isOutsideRange to use distance maps
Use a distance map to find the players in range quickly
2020-05-06 03:48:18 -04:00
Spottedleaf
b4e629a283
Use distance map to optimise entity tracker / Misc Utils
Use the distance map to find candidate players for tracking.

This also ports a few utility changes from Tuinity
2020-05-06 03:47:24 -04:00
Spottedleaf
d80d15174b
Optimize Entity Ticking to Loaded Chunks only
We retain a list of loaded entities specifically for this usage
2020-05-06 03:43:11 -04:00
MiniDigger
75e1e3b3e1 Mob Goal API 2020-05-05 18:05:27 +02:00
Aikar
c7bc393a87
Revert "Don't flush packet queue off main thread"
This reverts commit 1abd2bd279.

Sadly not gonna work due to server pings
2020-05-04 04:50:08 -04:00
Aikar
1abd2bd279
Don't flush packet queue off main thread
Increases risk of deadlock if a plugin using protocollib sends a packet
async, and then a listener then reads world state, and main thread is then
blocked waiting for the queue to flush.

This will break out of the synchronized block when it jumps to the netty event loop.

See: https://gist.github.com/aikar/e7abb2ba7059149d0a91f7a226e98590
2020-05-04 03:07:04 -04:00
Aikar
a4ed58a9ab
Clean up Direct Memory Region Files Fix for different Java versions
Java 9+ doesn't allow using the exposed cleanup method, but added
a new method on Unsafe to do it.

So have to detect java version and use the appropriate strategy.
2020-05-04 02:19:38 -04:00
Aikar
55e3501967
Set cap on JDK per-thread native byte buffer cache
See: https://www.evanjones.ca/java-bytebuffer-leak.html

This is potentially a source of lots of native memory usage.

We are clearly seeing native usage upwards to 1-4GB which doesn't make sense.

Region File usage fixed in previous patch should of tecnically only been somewhat
temporary until GC finally gets it some time later, but between all the various
plugins doing IO on various threads, this hidden detail of the JDK could be
keeping long lived large direct buffers in cache.

Set system properly at server startup if not set already to help protect from this.
2020-05-04 01:14:10 -04:00
Aikar
b5101f4f97
Cleanup Region Files Direct Memory on close
Mojang was semi leaking native memory here by relying on finalizers
to clean up the direct memory.

Finalizers have no guarantee on when they will be ran, and since this is
old generation memory, it might be a while before its called.
2020-05-04 01:08:51 -04:00
Aikar
81e655d7fa
Optimize Voxel Shape Merging
This method shows up as super hot in profiler, and also a high "self" time.

Upon analyzing, it appears most usages of this method fall down to the final
else statement of the nasty ternary.

Upon even further analyzation, it appears then the majority of those have a
consistent list 1.... One with Infinity head and Tails.

First optimization is to detect these infinite states and immediately return that
VoxelShapeMergerList so we can avoid testing the rest for most cases.

Break the method into 2 to help the JVM promote inlining of this fast path.

Then it was also noticed that VoxelShapeMergerList constructor is also a hotspot
with a high self time...

Well, knowing that in most cases our list 1 is actualy the same value, it allows
us to know that with an infinite list1, the result on the merger is essentially
list2 as the final values.

This let us analyze the 2 potential states (Infinite with 2 sources or 4 sources)
and compute a deterministic result for the MergerList values.

Additionally, this lets us avoid even allocating new objects for this too, further
reducing memory usage.
2020-05-03 23:02:52 -04:00
Aikar
ed9fc11fe3
Sync position on teleportation
We've seen many a cases where the "last good" x/y/z is desynced from
the x/y/z that is checked for moving too fast.

Theory is that when you have multiple movement packets queued up,
and the player is teleported after the first then the 2nd and 3rd come in,
it is triggering a massive movement velocity.

This will ensure that the servers position is synchronized anytime player is te

Fixes #3258
2020-05-03 15:29:53 -04:00
Aikar
9c326fceda
Nanothing to see here 2020-05-03 03:38:19 -04:00
Aikar
3e9fc24b66
Attempt to fix FastLogin maybe 2020-05-03 02:20:56 -04:00