Terraria 1.4.5.8 瓦片渲染期间因 .NET GC 导致间歇性 ~280 ms 冻结
Intermittent ~280 ms freezes caused by .NET GC during tile rendering
Terraria 1.4.5.8 在 Steam 平台瓦片渲染时因 .NET GC 触发间歇性 ~280–290 ms 冻结。性能跟踪显示主线程 GC 耗时约 283 ms,相当于 60 FPS 下 17 帧中断且音频线程不受影响。该问题约每几分钟复现,视频与控制停止而音频继续。
- Steam or GOG
- Steam
- Single Player/Multiplayer
- Single
- Operating System
- Windows
- Terraria Version
- 1.4.5.8
- Controls Used
- Keyboard/Mouse
Terraria intermittently freezes for a fraction of a second during normal gameplay. The video and controls stop responding during the freeze, but audio continues playing normally.
This occurs approximately every few minutes. It happens in both an existing world and a newly created world.
I did not previously experience this behavior, and other games on the same system (for example, Elden Ring) run without comparable stuttering.
I captured the problem using Windows Performance Recorder/Windows Performance Analyzer (WPR/WPA) and was able to isolate one of the freezes.
Performance trace findings
During a captured freeze, Terraria spends approximately 280–290 ms on its main game/render thread inside a .NET garbage collection.
The sampled call stack during the freeze is:
Terraria.Main::Draw
Main::DoDraw
Main::RenderToTargets
WorldSceneLayerTarget::UpdateContent
Main::RenderTiles
Main::DrawTiles
TileDrawing::Draw
TileDrawing::DrawSingleTile
clr.dll!JIT_NewArr1
clr.dll!AllocateArrayEx
clr.dll!Alloc
clr.dll!WKS::GCHeap::Alloc
clr.dll!WKS::gc_heap::try_allocate_more_space
clr.dll!WKS::gc_heap::trigger_gc_for_alloc
clr.dll!WKS::GCHeap::GarbageCollectGeneration
clr.dll!WKS::gc_heap::garbage_collect
clr.dll!WKS::gc_heap::gc1
[\noemote]
In this capture:
- TileDrawing:: DrawSingleTile: ~287.5 ms
- CLR allocation/GC path beginning at JIT_NewArr1: ~283.4 ms
- GC mark_phase: ~161.5 ms
- root scanning within the mark phase: ~134.8 ms
- GC planning phase: ~122 ms
At 60 FPS, the ~283 ms GC interval represents roughly 17 frame intervals, matching the visible freeze.
The trace also shows the XAudio2 audio thread continuing to execute during the GC, which appears consistent with the observed behavior: video/input freezes while audio continues.
I reproduced essentially the same call path in more than one performance capture.
Important qualification
TileDrawing:: DrawSingleTile appears to contain the array allocation that triggers the GC in the captured freezes. I do not know whether DrawSingleTile itself is responsible for the overall allocation pressure/live managed heap, or whether it is simply the allocation that crosses the GC threshold.
Other troubleshooting performed
I have tested:
- old and newly created worlds
- autosave disabled
- different lighting settings
- Subtle frame skipping
- Steam recording/overlay disabled
- Discord overlay not involved
These did not eliminate the freezes.
I initially suspected disk I/O and captured disk performance counters. The drive showed very low latency during testing (generally well below 2 ms), low active time, and essentially no meaningful disk queue. I was unable to correlate the freezes with storage stalls.
The WPR/WPA traces instead identified the long CLR GC execution on Terraria's main/render thread.
Reproduction
- Launch vanilla Terraria through Steam.
- Load a world.
- Play normally.
- After several minutes, a short freeze occurs.
- During the freeze, video and controls stop for roughly a fraction of a second while audio continues.
- The game then resumes normally.
The issue occurs repeatedly during a play session.
Additional diagnostic data
I have WPR/WPA ETL traces from the reproduction, including Microsoft symbols, CPU sampled/precise data, and .NET Runtime activity.
I can provide the ETL trace or additional WPA exports if they would be useful.
来源:Terraria Forum · forums.terraria.org