232 Commits

Author SHA1 Message Date
Dylan K. Taylor
44c791f03e Thread/Worker run() are now final, to set up common environment things 2019-06-06 16:44:32 +01:00
Dylan K. Taylor
e69ab60034 MemoryManager: use prefixed loggers 2019-06-04 13:49:07 +01:00
Dylan K. Taylor
cf0c0e72a9 Assume the player is online when they are, uh, assumed to be online
the checks removed here should never be hit under normal circumstances. If they were hit, they'd just conceal bugs which would cause a crash to happen later anyway.
2019-05-07 19:49:06 +01:00
Dylan T
3cd6e12e71
Renaming "Level" -> "World" (#2907)
This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages.

This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API.

This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
2019-05-07 14:47:28 +01:00
Dylan K. Taylor
752e398970 AsyncTask: TLS now supports storing multiple values (now requires a key/value pair) 2019-04-18 18:58:31 +01:00
Dylan K. Taylor
e62bbd4754 AsyncTask: added onError() main thread hook, closes #2512 2019-04-16 17:44:14 +01:00
Dylan K. Taylor
2c4f2810d2 AsyncTask: Remove misleading methods getFromThreadStore(),saveToThreadStore(),removeFromThreadStore()
These methods are commonly mixed up when we talk about thread-local storage. What these things actually do is store persistent data on the worker thread.
2019-04-02 14:57:11 +01:00
Dylan K. Taylor
23071d257e Extract process-related functions from Utils into a separate Process class 2019-03-24 18:57:32 +00:00
Dylan K. Taylor
808259dccd Introduce CancellableClosureTask
before anyone picks a fight about the naming, take it up with shoghi... let's be consistently wrong at least
2019-03-02 10:45:01 +00:00
Dylan K. Taylor
6c8fa8ae28 More nullable and void typehints 2019-03-02 10:29:11 +00:00
Dylan K. Taylor
0f2f05fbb9 Merge branch '3.6' 2019-02-22 18:14:17 +00:00
Dylan K. Taylor
4eaea54b0e TaskScheduler: fixed wrong typehints
These methods never return null.
2019-02-22 17:47:28 +00:00
Dylan K. Taylor
73a565355b Make some forced-optional nullable parameters non-optional, PHP 7.1 style
these parameters did not make any sense to be optional, but were forced to be this way because of the way nullable types worked before 7.1.
2019-02-22 12:54:00 +00:00
Dylan K. Taylor
d378371cc8 Transition to spl_object_id() 2019-01-26 15:06:38 +00:00
Dylan K. Taylor
bbc8bc4df5 Move some error handling stuff to SPL 2019-01-17 19:16:03 +00:00
Dylan K. Taylor
adc1069ed2 Merge branch '3.5' 2019-01-04 23:28:44 +00:00
Dylan K. Taylor
4b9a142a5d Import global functions and constants for enhanced performance
This is better for performance because these then don't need to be reevaluated every time they are called.

When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace.
This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified.

However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement.
But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations.
We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
2019-01-04 20:43:15 +00:00
Dylan K. Taylor
19fa6f5e8f Merge branch '3.5' 2019-01-03 15:44:48 +00:00
Dylan K. Taylor
6bd1491b8b AsyncPool: Apply a cooldown to workers to cut down unnecessary GC lag spikes
Since 3.2 there have been some runtime performance issues related to garbage collection and dynamic AsyncWorker booting. This is partly because of GC being dumb about shutting down what it thinks are "unused" workers. A worker which has been idle for a single tick is considered the same as a worker which has been idle for hours. The result of this is that on active servers, workers would get shut down and then immediately restarted because of something like chunk sending. Since booting an async worker is frightfully expensive, this causes lag spikes, which is obviously bad.

This commit changes the GC mechanism to only shutdown workers which have not been used for the last 5 minutes.
2019-01-03 15:06:53 +00:00
Dylan K. Taylor
e9d43aa44f Fixed MainLogger not being assigned as global on async workers 2018-12-28 12:55:49 +00:00
Dylan K. Taylor
05e968d9fd Merge branch 'release/3.4' 2018-12-04 18:40:54 +00:00
Dylan K. Taylor
a95694ed06 Add signature validation for some user-defined callbacks 2018-12-04 18:33:58 +00:00
Dylan K. Taylor
ed8569a3f4 Remove Collectable class, fix memory leak on AsyncTask fatal error 2018-11-05 17:26:22 +00:00
Dylan K. Taylor
6437078c8b TaskScheduler: remove deprecated constructor parameter 2018-11-04 23:30:04 +00:00
Dylan K. Taylor
0028ce0ed2 Merge branch 'release/3.4' 2018-11-04 23:25:05 +00:00
Dylan K. Taylor
e26af3fa1b TaskScheduler: don't catch unexpected exceptions
this means that errors in scheduled tasks which are uncaught will now cause a server crash.
2018-11-04 23:22:30 +00:00
Dylan K. Taylor
2a43d9ecb6 Merge remote-tracking branch 'origin/release/3.4' 2018-11-04 22:56:03 +00:00
Dylan T
755db3dac8
Added a ClosureTask implementation for easier task scheduling (#2497) 2018-11-04 22:55:40 +00:00
Dylan K. Taylor
1c9137aa94 Merge branch 'release/3.4' 2018-11-04 22:18:15 +00:00
Dylan K. Taylor
0543c17849 Merge branch 'release/3.3' into release/3.4 2018-11-04 22:15:46 +00:00
Dylan K. Taylor
046c39b02e Remove some Throwable abuse in AsyncTasks 2018-11-04 22:15:06 +00:00
Dylan K. Taylor
87b471ce0f AsyncPool: reverse e0d5c79848335ae9335686fd896e593324f2b191, don't catch unexpected exceptions thrown by onCompletion()
this should never throw an uncaught exception, and if it does it indicates broken code.
2018-11-04 22:09:30 +00:00
Dylan K. Taylor
652256a109 Merge branch 'release/3.4' 2018-11-03 16:58:19 +00:00
Dylan K. Taylor
9caf62778c AsyncTask: remove $serialize parameter from setResult()
Whether serialization is necessary can be determined automatically based on the type of variable.
2018-11-03 16:56:24 +00:00
Dylan K. Taylor
1b4c65e74d Merge branch 'release/3.4' 2018-11-03 12:12:59 +00:00
Dylan K. Taylor
f0182c9996 TaskHandler: remove incorrect internal warning
this is perfectly fine to use, and preferable to getting a cyclic ref to the scheduler. TaskScheduler->cancelTask() does pretty much the exact same thing, and the scheduler internals are designed to deal with this anyway.
2018-11-03 12:12:02 +00:00
Dylan K. Taylor
acd3116591 Merge branch 'release/3.4' 2018-11-01 15:51:50 +00:00
Dylan K. Taylor
ab48d85c35 Properly deal with anonymous tasks in timings 2018-10-31 18:51:30 +00:00
Dylan K. Taylor
212d72657a
AsyncPool: Switch to a more efficient collection algorithm, revamp internals (#2493)
This greatly improves GC performance by being more intelligent about how it collects garbage tasks. It knows that if X task in the queue is not finished, none of the tasks behind it can be finished either, so there's no point checking them.

This also presents the opportunity to cleanup a lot of async pool internals, so I've taken it and torched a lot of garbage.
2018-10-25 15:36:38 +01:00
Dylan K. Taylor
90482e79bc Merge branch 'release/3.4' 2018-10-21 18:23:54 +01:00
Dylan K. Taylor
45c9caa38c Fixup some formatting issues 2018-10-21 18:15:25 +01:00
Dylan K. Taylor
d583dc25c3 Merge branch 'release/3.3' 2018-10-10 13:45:31 +01:00
Dylan K. Taylor
2858db430e Fixed AsyncTask publishProgress() race condition on task exit
It's possible for a progress update to be lost due to the task finishing before the main thread found the progress update.
2018-10-10 13:41:15 +01:00
Dylan K. Taylor
24677e1d79 Prevent undefined behaviour when accessing async worker thread-store from outside the worker itself 2018-10-08 13:01:12 +01:00
Dylan K. Taylor
a0f3c03b50 oopsie woopsie
I made a fucky wucky! a wittle fucko boingo!
2018-10-08 12:59:47 +01:00
Dylan K. Taylor
6ac0c517f5 Improve and simplify AsyncTask thread-local storage
This is now self-maintaining and doesn't rely on the async pool to wipe its ass on task completion. Instead, the garbage collector will cause thread-local data to be automatically released when the async task is garbage-collected on the main thread.
2018-10-08 12:48:44 +01:00
Dylan K. Taylor
e0574008b4 AsyncPool: Move removeTasks() functionality inside shutdown()
there's no need for a loop if we just have the workers shutdown directly, because they'll block until all tasks are done anyway.
2018-09-12 18:08:42 +01:00
Dylan K. Taylor
37190c9a65 Apply typehints to all AsyncTask methods
Since we're breaking API here anyway, no point in holding back on this.
2018-09-10 15:54:01 +01:00
Dylan K. Taylor
d62e00cc74 AsyncPool: Remove Server dependency (API breaks included)
This brings two plugin-breaking changes: AsyncTask->onCompletion() and AsyncTask->onProgressUpdate() no longer accept Server parameters.

This now allows for the functionality of AsyncPool and AsyncTask to be tested outside of a Server.
2018-09-10 15:48:59 +01:00
Dylan K. Taylor
83077309ef Merge branch 'release/3.2' 2018-08-04 16:03:46 +01:00