branchrust_reboot/main/mt_snapshot_savingcancel
192 Commits over 62 Days - 0.13cph!
Clean: remove MutexPool
- ran codegen
Tests: booted craggy, ran print_memory
Optim: defer loading of small atlases, and pack them into ui dynamic bundle
Prevents loading of ~30 atlases (original and small), which saves another ~250MB
Tests: booted stnadalone build and compared snapshots. navigated to store with failloads and made sure small atlas versions are picked up
Bugfix: ensure thread-static buffer is initialized on all threads
Tests: booted into craggy
Bugfix: make NetWrite.String thread safe by marking buffer ThreadStatic
Tests: with jobs 4 spawned 20 cows on craggy
Bugfix: avoid MRU modification when accessing it in BasePlayer.Save
Originally intended implementation, looks like I derped awhile ago.
Tests: booted into craggy with Jobs 4
Bugfix: avoid thread race modifying same list when saving DisplayBoxStorage
- cache is now an array rather than a list
Tests: setup a display box storage, showed items in it, could see contents inside change
Bugfix: eagerly instantiate PaintballColorLookup to avoid it happening on Save, which is not mt safe
Tests: spawned on craggy, switched on jobs 4 and shot with a paintball gun
Bugfix: cache owner entity of HittableByTrains on init
Avoids lookups while running SaveComponent
Tests: spawned a wooden double barricade with jobs 4 enabled
Bugfix: make Underwear.ValidateForPlayer MT friendly on server
Fixes BasePlayer saving throwing unity exceptions
Tests: changed underwear with Jobs 4
Bugfix: make FishMount.Save mt friendly - cache fish container index
Tests: placed a fish in a trophy display with Jobs 4
Update: wrap InvokeHandler internals in DebugMTLock
Tests: booted on craggy and ran around with EnableDebugMTLock
Update: add single-thread reentrant support to DebugMTLock to avoid deadlocks
- added unit tests
Because of course InvokeHandler is non-trivially recursive
Tests: uni tests
Update: Move UnsafeScriptingAccess and DebugMTLock to Facepunch.UnityEngine
- Cleanup empty asms
Tests: ran relevant unit tests
Update: explicitly capture callstack when DebugMTLock is tripped
- frame count can be limited to via unsafe.DebugMTLockMaxFrames (def 5)
Tests: ran unit tests
New: DebugMTLock - a named lock guard that print an error on concurrent access
- controlled by Unsafe.EnableDebugMTLock, disabled by default
- codegen, unit tests
Need it to help chase down unobvious thread races, like InvokeHandler
Tests: ran unit tests
Optim: Jobs 4 - reduce server.ParallelNetworkQueueBatchSize to 16 by default
256 was waaay to high for the per-frame workload we get, it basically disabled parallelization
Tests: none, trivial change
Bugfix: fix 6 TestMTSave failures
No legit mt issues, just new entity types with missing unit test setup
Tests: ran all TestMTSave tests, pass
Bugfix: make card table saving MT-friendly
Done by removing the concept of item "busy" or "locking" - was never set but checked against Time.time
Tests: none, trivial change
Bugfix: cache rocket ammo def to avoid get_gameObject calls in AttackHelicopterRockets
Tests: spawned attack heli and geared it up - could see them in inventory
Bugfix: avoid a thread race on PlayerState MRU dictionary when saving BasePlayer
- use readonly access in Save that doesn't update MRU
- push to cache on player connect
Tests: ran CraggyIsland_missions, completed a mission - saw states change in UI
Update: avoid calling db queries when saving BasePlayer.PersistentPlayerInfo
- instead resolved on player join
It should be safe according to docs(mt calls are serialized), but this way is just simpler.
Tests: booted into craggy
Bugfix: use transform handles when saving ApartmentRoom.GetDailyUpkeepCost in Jobs 4 mode
Bypasses transform access which avoids tripping up on unity MT checks
Tests: rented a room in Jobs 4 mode, had a breakpoint in the code - no exceptions
Bugfix: cache ammo for heli turret, avoid TryGetComponent in Save which is not safe in MT
Tests: spawend a heli, setup an ak turret with 100 bullets, shot in Jobs 4 mode - no errors
Bugfix: remove duplicate transformHandle property
Prevents error in editor about duplicate serialization. Though the member is private and shouldn't serialize anyway?
Tests: tried opening & saving the rpefab, but couldn't cause original error
Bugfix: use cached time snapshot for server occlusion snapshot sending
Prevents Time usage in worker threads
Tests: none, trivial change
Bugfix: rewrite ExactArrayPool to be a ConcurrentDictionary
Was not MT safe for Jobs 4 parallel serialization as it could lazy initialize
Tests: TestMTSave
Update(tests): make SendEntityUpdates perf test spawn as many recievers as threads available
Allows to fully saturate the CPU in a test, giving a bit fairer comparison between Jobs 3 and 4
Tests: ran new test
Clean: fixed whitespacing
Tests: none, trivial change
Buildfix: add missing server guard
Tests: compile sim
Update: add an default TransformHandle check to TransformEx.Unsafe.ExtractTranformAccess
Better we lose a smidge of perf than have a native crash
Tests: ran all TestMTSave
Update: add GetPosMT and GetRotMT to TransformEx
- bugfix Elevator Save accessing transform
chcked internals, should be safe
Tests: fly across all of 2.5k procgen, no errors triggered
Bugfix: avoid resolving transformHandle on an optional BatteringRam.doorPhysicsHinge
Checked other cases I've modified, rest are required
Tests: none, trivial change
Bugfix: resolve game controlelr at init of BaseCardGameEntity
- use cached controller instead of trying to lazy create it in Save
Avoids invoking non MT-safe APIs in save
Tests: visited bandit camp on procgen, no errors. Ran TestMTSave tests
Bugfix: avoid NRE if bike doesn't have a sidecar
Tests: spawned a motorbike
Update(tests): TestServer now also creates a dummy BiomeMap
Not sure why pre-merge TestMTSave(GrowableEntity) didn't trip over, but sorted now
Tests: all TestMTSave
Clean: add comments for new perf test
Tests: none, trivial change