Commit graph

4767 commits

Author SHA1 Message Date
Spottedleaf
aff206ef81 Optimize WorldBorder collision checks and air
Port part of leafs changes from Tuinity, will worry about rest later with larger changes coming
2020-05-10 22:49:58 -04:00
Aikar
02dcaa0af7 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
1c0dde5df5 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
b74f95d9f9 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
a26aabf9d0 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:36:35 -04:00
Aikar
ee714e312d Send LOGIN protocol packets immediately - Fix disconnect during async prelogin 2020-05-10 03:12:05 -04:00
Aikar
bd2a5095d3 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:26:21 -04:00
Aikar
5eea746c78 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
56d8694bd9 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-09 22:30:28 -04:00
Aikar
04becc8a1c Ensure chunks loaded on respawn for suffocation check 2020-05-09 21:13:30 -04:00
Aikar
f36b2a2c05 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:18:26 -04:00
JellySquid
3229702834 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-04-22 17:11:50 +02:00
Aikar
f0b502d564 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 15:47:08 -04:00
Aikar
7c9097159c 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
2c648ff35f 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
2a0201d137 Add Spawn Entity SpawnReason API
So you can specify why an entity is spawning, ie NATURAL
2020-05-09 13:11:43 -04:00
Aikar
d816beaced 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
e9fcee1190 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
c6b756d121 Fix world unload toLowercase - Fixes #3326 2020-05-09 10:59:10 -04:00
virustotalop
61142982e0 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-04-16 20:57:02 -07:00
Aikar
b57f715649 Fix CraftServer.unloadWorld Leak
The dimension manager was still registered which leaked the entire World
2020-05-08 20:40:42 -04:00
Aikar
8c7b991317 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
1404a3b655 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
e2fb92fbb6 Revert Nibble patch, causing issues still 2020-05-07 05:30:40 -04:00
Aikar
7f8e789cf3 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
9204e8c641 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
bb418b5532 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
58c0bbdd11 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
7ec3cf8948 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
f410ec4423 Revert loaded entity list (#3304) 2020-05-06 09:31:29 -07:00
Spottedleaf
0f2383acc0 Move another NetworkManager util into the inner class (#3303)
Those poor souls running outdated ProtocolLib.
2020-05-06 08:07:51 -07:00
Spottedleaf
f1b980c22f 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 07:57:18 -07:00
Aikar
d2a300598c 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
1127deb87d Rebuild all patches using the new rebuild pattern 2020-05-06 05:48:49 -04:00
Mariell Hoversholm
45dc9552b1 Add villager reputation API 2020-04-22 23:46:57 +02:00
Minecrell
9856baa629 Speed up rebuilding patches and reduce diff 2020-05-06 11:31:08 +02:00
Aikar
fd5c98a9ef 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:22:03 -04:00
stonar96
30d007b163 Anti Xray cleanup
Undo the accidental renaming of a method in e45e15c
Aikar wanted to rename DataPalette#getDataBits(T object) to getOrCreateIdFor
in e45e15c 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
584c2fbe18 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:49:52 -04:00
Spottedleaf
fbaa9ae1f3 Stop copy-on-write operations for updating light data
Causes huge memory allocations + gc issues
2020-05-06 03:48:56 -04:00
Spottedleaf
7307189ab2 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
fbe8958237 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:44:47 -04:00
Spottedleaf
444dd5a0c6 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
Nassim Jahnke
2baf3d7f5b Add item slot helper methods for various inventories (#3221) 2020-05-06 01:49:16 +02:00
MiniDigger | Martin
d17856519c Mob Goal API 2020-04-30 17:18:45 +02:00
Aikar
3e4fec905c Revert "Don't flush packet queue off main thread"
This reverts commit e3105bc57a.

Sadly not gonna work due to server pings
2020-05-04 04:50:08 -04:00
Aikar
e3105bc57a 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
5a8b71725f 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
cc88bc65e1 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
8756fc733c 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:03:57 -04:00