Commit Graph

4786 Commits

Author SHA1 Message Date
Aikar 146b99080c
Improve ChunkMapDistance.b crash fix to clean up properly
There is some vanilla level bug where this tracking state appears
to get messed up and player doesn't exists in chunk its trying to untrack.

We returned early to prevent crashing, but I suspect if there was a level being
tracked for the chunk, it got leaked due to the early return.

So going to ensure we clean up the level tracker when this state occurs.

This may help with any leaked chunk issues.
2020-06-09 23:05:43 -04:00
Aikar 2c4499b71c
Show Plugins Event Listeners under Combined Total in Timings 2020-06-09 21:48:35 -04:00
Aikar c5c909c9af
Improve Plugin Ticket Management
Now supports async chunk access even though doing that is bad
and shouldn't be done anyways since we force you back to main, itll
now just delay the ticket add to main the same way.

Now only add the ticket if the plugin CAUSED the chunk load, so no longer
adds ticket if the chunk was already loaded.

Additionally, cap chunk ticket limits to 1 second (Effectively ignoring chunk-gc config
unless the config is lower than 20 ticks)

Fixes #3533
2020-06-09 21:15:36 -04:00
Luracasmus b20529f3d3
Update to HTTPS in README (#3460)
Update URLs to HTTPS in README.md.
2020-06-09 04:12:43 -04:00
stonar96 de6dfedfef
Make Anti-Xray multithreaded (#3520)
Obfuscate multiple chunks at a time over the server thread pool.

Will speed up chunk processing when anti xray is enabled.

Co-authored-by: Aikar <aikar@aikar.co>
2020-06-09 04:12:20 -04:00
Aikar 531c4b3fd1
Add PluginTickets to API Chunk Methods
Like previous versions, plugins loading chunks kept them loaded until
they garbage collected to avoid constant spamming of chunk loads

This adds tickets to a few more places so that they can be unloaded.

Additionally, this drops their ticket level to BORDER so they wont be ticking
so they will just sit inactive instead.

Using .loadChunk to keep a chunk ticking was a horrible idea for upstream
when we have TWO methods that are able to do that already in the API.

Not adding it to .getType() though to keep behavior consistent with vanilla.
2020-06-09 03:43:11 -04:00
Aikar b2d81e21c5
Improve Chunk Prioritization and Internal Scheduler
In previous MC versions, we had a rather simple internal scheduler
for delayed tasks that would just keep pushing task back until desired
tick was reached.

The method it called to schedule the task changed behavior in 1.14, and now
this scheduler is not working nowhere near what it was supposed to be doing.

This was causing long delayed task to eat up CPU (In Oversleep for example)

Rewrite this to just use the CraftScheduler for scheduling delayed tasks.

Once this was fixed, it became quite clear the code that delayed ticket
additions for chunks based on distance was clearly not right, as it was
tested on the previous broken logic.

So the ticket delay process has been vastly revamped to be even smarter.
Chunks behind the player can load slower than the chunks in front of the player.
We also can delay ticket adding until one of its neighbors has loaded, as
this lets us get a smoother spiral out for the chunks (minus frustum intent).

Additionally on frustum previous commit inadvertently broke frustum trying to
fix an issue when the real fix lied elsewhere, so restore chunk priority so
it works again.
2020-06-09 03:17:25 -04:00
Aikar 24a2e80431
Improve Login to use Urgent priority - improves login chunk load times 2020-06-08 21:47:39 -04:00
Aikar 9dfe1321d5
Delay Chunk Unloads based on Player Movement
When players are moving in the world, doing things such as building or exploring,
they will commonly go back and forth in a small area. This causes a ton of chunk load
and unload activity on the edge chunks of their view distance.

A simple back and forth movement in 6 blocks could spam a chunk to thrash a
loading and unload cycle over and over again.

This is very wasteful. This system introduces a delay of inactivity on a chunk
before it actually unloads, which will be handled by the ticket expiry process.

This allows servers with smaller worlds who do less long distance exploring to stop
wasting cpu cycles on saving/unloading/reloading chunks repeatedly.
2020-06-08 18:17:11 -04:00
Aikar f0409edcd7
Drop Close region files patch, doesn't add any value.
Upon further knowledge of the system, it is known that region files
are closing properly, as well as this didn't help native memory use anyways.

This patch also caused issues compiling on a newer JDK being able to
release the jar to java 8 users.
2020-06-08 17:07:23 -04:00
Aikar 700070c5e6
Fix undesirable behavior around world level changes due to priority
priority tickets being added at 33 was hurting sync EMPTY and lesser requests.

this was likely the source of recent treasure map issues.

This then further hurt nether portal travel too. lots of oddness around.

This also avoids scheduling a level change on ticket removal when the level
is unchanged, as well as ditches CB's horrible change to not letting
you access an unloading chunk which should be valid to cancel the unload
2020-06-08 17:03:42 -04:00
Aikar 34e5942bf0
Fix timings task name generation for extreme cases - Fixes #3499
I'm going make a class, and in that class i'm going to
make a method. And in that method, I'm going to make a local class.

And then in that local class, I'm going to make another inner class.

I heard you like complex class trees.
2020-06-08 12:22:40 -04:00
Aikar 5e3bacbced
Ensure ThreadDeath propagates fully - Fixes #3521 2020-06-08 11:54:12 -04:00
Aikar 9fa6ba267c
Optimize Light Engine
Massive update to light to improve performance and chunk loading/generation.

1) Massive bit packing/unpacking optimizations and inlining.
  A lot of performance has to do with constant packing and unpacking of bits.
  We now inline a most bit operations, and re-use base x/y/z bits in many places.
  This helps with cpu level processing to just do all the math at once instead
  of having to jump in and out of function calls.

  This much logic also is likely over the JVM Inline limit for JIT too.
2) Applied a few of JellySquid's Phosphor mod optimizations such as
  - ensuring we don't notify neighbor chunks when neighbor chunk doesn't need to be notified
  - reduce hasLight checks in initializing light, and prob some more, they are tagged JellySquid where phosphor influence was used.
3) Optimize hot path accesses to getting updating chunk to have less branching
4) Optimize getBlock accesses to have less branching, and less unpacking
5) Have a separate urgent bucket for chunk light tasks. These tasks will always cut in line over non blocking light tasks.
6) Retain chunk priority while light tasks are enqueued. So if a task comes in at high priority but the queue is full
   of tasks already at a lower priority, before the task was simply added to the end. Now it can cut in line to the front.
   this applies for both urgent and non urgent tasks.
7) Buffer non urgent tasks even if queueUpdate is called multiple times to improve efficiency.
8) Fix NPE risk that crashes server in getting nibble data

Fixes #3489
Fixes #3363
2020-06-07 20:31:29 -04:00
Aikar dfd3848ee6
Use seed based lookup for Treasure Maps - Fixes lag from carto/sunken maps 2020-06-07 19:28:58 -04:00
Aikar 74dcb3c923
Revert "Fix enchantment costs (#3519)"
This reverts commit 6d72ea1659.
2020-06-07 19:13:41 -04:00
Alexander 6d72ea1659
Fix enchantment costs (#3519) 2020-06-07 17:53:49 -04:00
Max Lee 68cc8d79b2
Maps shouldn't load chunks (#3518)
Previously maps would load all chunks in a certain radius depending on
 their scale when trying to update their content. This would result in
 main thread chunk loads when they weren't really necessary, especially
 on low view distances or "slow" async chunk loads after teleports or
 other prioritisation.

 This changes it to only try to render already loaded chunks based on
 the assumption that the chunks around the player will get loaded
 eventually anyways.
2020-06-07 16:57:52 -04:00
chickeneer e7cf34a039
Fix villager trading demand MC-163962 (#3498) 2020-06-07 14:41:32 -04:00
oxygencraft 51f9edf22d
Change name and id to get from profile in AsyncPlayerPreLoginEvent (#3511)
Co-authored-by: Daniel Ennis <aikar@aikar.co>
2020-06-07 14:36:13 -04:00
Shane Freeder 225484ccef
Fix SoundEffectType#getHitSound OBFHELPER 2020-06-07 09:51:00 +01:00
Aikar b75eeca0e5
Boost light task priority to ensure it doesnt hold up chunk loads
Run urgent as 2 so urgent light can run as 1 (light run at chunk -1 for loading purposes)
2020-06-03 01:46:09 -04:00
Aikar 3d2bc848c1
Ensure VillagerTrades doesn't load async - fixes #3495
In rare cases, this class could potentially be loaded from
the chunk threads causing it to initialize async and cause errors.

This would then break the server and chunk saving.

So ensure its loaded at start of server to avoid this.
2020-06-03 00:00:17 -04:00
Aikar e470f1effe
Add more information to Timing Reports
Still needs front end changes to see it yet though.

1) Adds Game Rules per world
2) Adds View distances per world
3) Removes extra garbage on lambda task names
4) Adds more memory information such as native load
5) Adds load average for non crap operating systems.
6) Fixes online mode showing false when privacy=true
7) Adds Data packs loaded
2020-06-02 23:30:58 -04:00
Aikar f4a47db699
Improve Thread Pool usage to allow single threads for single cpu servers
Switch to a standard fixed size ThreadPoolExecutor as we don't use the
advanced capabilities of a ForkJoinPool.

ForkJoinPool does not allow single threads, and really rather not use
2 different executor types based on core count.

Also, change thread priorities so that main thread is prioritized by
the OS at a higher priority than the other threads. May not help too much
but it at least signals the OS the information to know main is more important.
2020-06-02 02:19:07 -04:00
Aikar a4fe910f57
Fix sounds when using worldedit regen command
Locks dimension manager to the first world its used with.

WE is creating a temp world and the world ref on that manager
is getting changed to the temp world.

This would of also caused a memory leak of that temp world too.
2020-06-02 01:29:18 -04:00
Aikar 70ad51a80c
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

My recent work on serialization is now in CraftBukkit so was able to drop the patch and Paper
is now consistent with upstream.

Bukkit Changes:
e2699636 Move API notes to more obvious location

CraftBukkit Changes:
1b2830a3 SPIGOT-4441: Fix serializing Components to and from Legacy
2020-06-02 01:29:18 -04:00
Aikar d7cfa4fa5c
Improve legacy format serialization more
This should now complete legacy serialization to avoid ever
changing the output content.

This removes the concept of "Default Color" from the method as
that entire concept was flawed and broke the intent of chat components.

Going to actually PR this patch to Spigot soon.

This now puts us back at a point where any data saved pre Spigot
breaking things will still save back the exact same way as before,

but new component -> legacy will now be fixed to not insert undesirable
default colors (such as black) into the legacy string, and instead use
the proper reset code.

This means you can now safety get the text from a book and
put it in chat or an entity display name without worry about black
color codes or other undesired color codes leaking into the new
context where that color doesn't make sense.
2020-05-31 22:13:17 -04:00
Shane Freeder d6eda567ff
Provide a useful PluginClassLoader#toString
There are several cases where the plugin classloader may be dumped to the logs,
however, this provides no indication of the owner of the classloader, making
these messages effectively useless, this patch rectifies this
2020-05-31 15:38:18 +01:00
Aikar a3fdafbd11
Restore Serialization Improvements again, wasn't an issue.
I was a little quick to jump to blame this patch as cause of an issue,
but appears it was not the source for what I saw that made me revert this.
2020-05-31 05:01:26 -04:00
Aikar 0e441c7960
Revert "Improve Chat Component Legacy Serialization more"
This reverts commit 53ef67b88d.

Seems to be having undesired impact, will need to polish more.
2020-05-31 04:08:03 -04:00
Aikar 53ef67b88d
Improve Chat Component Legacy Serialization more
This brings chat componenent serialization to 100% accuracy so
that any text input in the legacy format, converting to comps and
then back to legacy will result in identical results.

If the user explicitly sets a color as prefix to a string, it is retained,
even if that color matches the default.

This also helps improve dealing with the empty string wrappers Bukkit creates.

A unit test has been added to verify this behavior.
2020-05-31 03:20:31 -04:00
wea_ondara afc1fcfc2e
Fix serialization of colors from components
This patch fixes the serialization of display names, item lores and
other things which use strings with color codes. The old implementation
deleted the color codes at the beginning of the resulting string if it
matched the default color passed to the conversion function. This
resulted in items having a black display name losing the black color
code in the beginning of the text when the item was serialized (e.g.
saving an ItemStack in a Yaml config).

Spigot has now made the issue worse and expanded the scope to more places.
2020-05-30 23:31:06 -04:00
Aikar eaa76a3115
Add Villager Tasks to EAR inactive tick to keep behavior
Stuff like restocking trades and reputation changes can happen when
a Villager is out of Activation Range now.
2020-05-30 04:54:40 -04:00
Aikar 357b52fd98
Improve Chunk Prioritization / Load Order
1) Improve frustum to look more at the near chunks and frontal chunks only instead of 1 large single look up.
2) Delay adding 33 tickets based on view distance and lower their task priority. This will slower roll out the spiral
3) Chunks behind the player have additional delay on loading, favoring chunks in front of the player.

This has benefit that if faster traveling, some of the chunks will be cancelled / not loaded.

This should reduce pressure on chunk loading, as well as reduce loading/unloading unnecessary chunks while moving.
2020-05-30 03:51:07 -04:00
Aikar a76bc4029d
Improve Chunk Status Transition Speed
When a chunk is loaded from disk that has already been generated,
the server has to promote the chunk through the system to reach
it's current desired status level.

This results in every single status transition going from the main thread
to the world gen threads, only to discover it has no work it actually
needs to do.... and then it returns back to main.

This back and forth costs a lot of time and can really delay chunk loads
when the server is under high TPS due to their being a lot of time in
between chunk load times, as well as hogs up the chunk threads from doing
actual generation and light work.

Additionally, the whole task system uses a lot of CPU on the server threads anyways.

So by optimizing status transitions for status's that are already complete,
we can run them to the desired level while on main thread (where it has
to happen anyways) instead of ever jumping to world gen thread.

This will improve chunk loading effeciency to be reduced down to the following
scenario / path:

1) MAIN: Chunk Requested, Load Request sent to ChunkTaskManager / IO Queue
2) IO: Once position in queue comes, submit read IO data and schedule to chunk task thread
3) CHUNK: Once IO is loaded and position in queue comes, deserialize the chunk data, process conversions, submit to main queue
4) MAIN: next Chunk Task process (Mid Tick or End Of Tick), load chunk data into world (POI, main thread tasks)
5) MAIN: process status transitions all the way to LIGHT, light schedules Threaded task
6) SERVER: Light tasks register light enablement for chunk and any lighting needing to be done
7) MAIN: Task returns to main, finish processing to FULL/TICKING status

Previously would have hopped to SERVER around 12+ times there extra.
2020-05-30 01:12:18 -04:00
Aikar 7a2b345b55
Synchronize DataPaletteBlock instead of ReentrantLock
Mojang has flaws in their logic about chunks being concurrently
wrote to. So we constantly see crashes around multiple threads writing.

Additionally, java has optimized synchronization so well that its
in many times faster than trying to manage read wrote locks for low
contention situations.

And this is extremely a low contention situation.

Fixes #3293
Fixes #2493
2020-05-29 20:36:42 -04:00
Aikar a8ef0a93b9
Drop remove leaked chunk patch - causing many issues
I'm hoping the other fix in 324 for the level map getting corrupted
fixes the real issue and this isn't needed anymore, but i suspect it is

will wait until more study can be done though.

Fixes #3469
2020-05-29 03:32:13 -04:00
Aikar ff4ca31f0d
Fix premature unloading of neighbor chunks for world gen
We must check the level tracker as ticket levels add "virtual"
tickets to neighbors.

Also added neighbor tracking during generation to be extra safe.

Fixes #3465
Fixes #3451
Fixes #3459
2020-05-28 22:59:40 -04:00
Aikar fde81356bb
Fix Chunks unloading immediately for priority access - Fixes #3461
Adding a priority ticket was apparently causing the level tracker
to immediately unload the chunk.

That code is scary
2020-05-28 22:57:27 -04:00
Aikar 9980f427db
Fix some logic on villager poi max attempts
Hopefully will help #3462
2020-05-28 20:45:36 -04:00
Aikar 919ab67a13
Fix concurrency issue in light engine (Vanilla bug)
Mojang implemented a cache like chunks have, but this cache
is accessed by multiple threads and is totally not safe.

So just remove it

Fixes #3466

Also missed a pooled nibble release, so slid that in there too.
2020-05-28 20:37:40 -04:00
Spottedleaf 0d5ec65372
Cleanup async chunks (#3456)
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
2020-05-28 19:34:58 -04:00
Shane Freeder c3c005c947
Updated Upstream (Bukkit/CraftBukkit) (Fixes #3443)
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:
d6db2839 #497: Add Material#getCraftingRemainingItem() to get item left behind after crafting
1c2eaf96 SPIGOT-5748: Add instant effect potion break to the Effect enum

CraftBukkit Changes:
aae46f82 #665: Add test for Material#getCraftingRemainingItem()
cfeef75c SPIGOT-5749: ItemMeta serializing to YAML not saving black colour code
eb1b19d9 SPIGOT-5748: Add instant effect potion break to the Effect enum
2020-05-28 12:22:50 +01:00
Aikar b0b54e4ef3
Optimize Villager Pathfinding - Massive Villager Improvement
This change reimplements the entire BehaviorFindPosition method to
get rid of all of the streams, and implement the logic in a more sane way.

We keep vanilla behavior 100% the same with this change, just wrote more
optimal, as we can abort iterating POI's as soon as we find a match....

One slight change is that Minecraft adds a random delay before a POI is
attempted again. I've increased the amount of that delay based on the distance
to said POI, so farther POI's will not be attempted as often.

Additionally, we spiral out, so we favor local POI's before we ever favor farther POI's.

We also try to pathfind 1 POI at a time instead of collecting multiple POI's then tossing them
all to the pathfinder, so that once we get a match we can return before even looking at other
POI's.

This benefits us in that ideally, a villager will constantly find the near POI's and
not even try to pathfind to the farther POI. Trying to pathfind to distant POI's is
what causes significant lag.

Other improvements here is to stop spamming the POI manager with empty nullables.
Vanilla used them to represent if they needed to load POI data off disk or not.

Well, we load POI data async on chunk load, so we have it, and we surely do not ever
want to load POI data sync either for unloaded chunks!

So this massively reduces object count in the POI hashmaps, resulting in less hash collions,
and also less memory use.

Additionally, unemployed villagers were using significant time due to major ineffeciency in
the code rebuilding data that is static every single invocation for every POI type...

So we cache that and only rebuild it if professions change, which should be never unless
a plugin manipulates and adds custom professions, which it will handle by rebuilding.
2020-05-27 01:35:36 -04:00
Aikar 33a2134b65
Workaround for really evil plugins breaking sounds
Some plugins are doing really really bad things to worlds breaking the
ability to send sounds to some users.

So creating another reference to the player chunk map that plugins wont be breaking, and
print a stack trace at world creation if we ever get an expected world state to identify
who is doing it!

If we encounter this illegal state, we fall back to the old method of sending sounds, so
sending sounds will still work, just less effecient.
2020-05-27 01:00:43 -04:00
Aikar b88ee11f5a
Don't unregister the primary dimensions on world unload 2020-05-27 00:15:57 -04:00
Aikar 21f9efa2ca
Improve implementation of chunk leak clean to not run as often 2020-05-25 21:42:53 -04:00
Aikar 7ee711460f
Add missing null check for structure start chunk access
Spigot made structure start not load chunks, but forgot to null check
the result...

This likely never blew up before due to the chunk leak issue, but now
that leaky chunks are cleaned up, it was identified.
2020-05-25 14:19:11 -04:00
Aikar b12177fb04
One more to seal the deal to improve unloading inactive chunks
While last was mostly there, still had some slight risk of unloading
before it was fully finished.

So just going to bump the delay to 3 minutes to be safe. Better than
forever at least.

Was really hoping we could unload them as soon as they were done to
any memory prematurely promoting to old generation, but guess we can't.
2020-05-25 13:09:56 -04:00