S&box Wiki
Home
/
Edit Hotload Performance
View
Edit
History
No Category
Developer Overview
The Project System
Publishing To Asset Party
Getting Started With Hammer
Mapping Basics
Mapping Entities
Advanced Mapping Techniques
Getting Started with Modeldoc
Animgraph & Animation
Physics
Modeldoc Nodes
Advanced Modelling
UI Basics
Styles & Stylesheets
Razor Templates
Game Menus
Materials
Built In Shaders
Shaders
Shader Reference
Sounds & Audio
Particles
Getting Started
Making Games
Input
Networking
Physics
Rendering
Editor & Tools
VR
Misc
Playing Guides
Console Commands & Variables
Dedicated Server
Log in to edit
Hotload Performance
<cat>Code.Editor</cat> <title>Hotload Performance</title> Here's some tips in case hotloading code changes to your addon is getting too slow. Our hotloading system needs to go through every object in memory, replacing any from the old DLL with one from the new DLL. This can get slow if you've got huge data structures with millions of objects. Some things to keep in mind: * Arrays of primitive types (`byte`, `int`, etc) survive the hotload without getting processed, which is very quick * Arrays of custom struct types that only contain value types can be copied across very quickly too * Arrays of any other custom types will have each item processed one-by-one, which can be much slower # Find out what's slow You can find out which objects are the slowest to replace by setting this console variable: ``` hotload_log 2 ``` This will log a bunch of timing info to the console after each hotload, for both server and client DLLs. The output will look like this: ``` Server Hotload processed 3,272,107 instances in 3.65s ---------------------------------------------------------------------------------------- | MinimalExample.MinimalPlayer.Example | 1000000 | 1321.7ms | | [StaticField] Sandbox.InteropSystem::Address | 1000000 | 1321.7ms | ---------------------------------------------------------------------------------------- | MinimalExample.MinimalPlayer.Example[] | 2048000 | 859.6ms | | [StaticField] Sandbox.InteropSystem::Address | 1024000 | 793.7ms | | [StaticField] MinimalExample.MinimalPlayer::_task | 1024000 | 66.0ms | ---------------------------------------------------------------------------------------- | Sandbox.Prop | 644 | 120.2ms | | [StaticField] Sandbox.InteropSystem::Address | 644 | 120.2ms | ---------------------------------------------------------------------------------------- ... ``` There will be a table for each type encountered, with the second column counting how many instances were seen, and the last column the time taken to process all the instances. The types are listed in descending order of time taken. You can ignore the rows starting with `[StaticField]` for now, they describe how the instances were found. From the example above, we can see processing `MinimalExample.MinimalPlayer.Example` instances is taking the bulk of the hotload time. # Using SkipHotload When you've found what types are slow to process, you can tell the hotloading system to just skip over fields and properties containing instances of those types. When a field or property is skipped, it will be left uninitialized after the hotload. That means `null` for reference types, or `default(T)` for value types. Continuing with the example above, we've worked out a property `BigList` is holding all the instances that hotload is taking ages to process. We can skip that property with the `[SkipHotload]` attribute: ``` [SkipHotload] public List<List<Example>> BigList { get; set; } ``` Now hotloading takes much less time: ``` Server Hotload processed 231,741 instances in 1.12s --------------------------------------------------------------------------------------------- | Sandbox.Prop | 644 | 108.0ms | | [StaticField] Sandbox.InteropSystem::Address | 644 | 108.0ms | --------------------------------------------------------------------------------------------- ... ``` However that property is now `null` after hotload, so skipping is only useful for data structures that you can generate again (and more quickly than it would take hotload to process). For example, your type might contain some raw data in a `byte` array that doesn't need to be skipped, and also some larger uncompressed representation of the same data for live use that you can regenerate after hotload is done. # Hotload callback interfaces For cases where you want to repopulate skipped fields, the containing type can implement `IHotloadManaged`. This has two methods that will be called by the hotloading system: `IHotloadManaged.Destroyed` is called on the old instance, and `IHotloadManaged.Created` is called on the new one that replaces it. In `Destroyed` you can populate a `state` dictionary with values to bring over to the new instance, which get passed to `Created`: ``` void IHotloadManaged.Destroyed(Dictionary<string, object> state) { state["Example"] = BigList.Select(x => x.Count).ToArray(); } void IHotloadManaged.Created(IReadOnlyDictionary<string, object> state) { var example = (int[])state["Example"]; // ... repopulate big list ... } ``` You'll want to only store stuff in the dictionary that is quick for hotload to process, like arrays of primitive types. # Fast-path hotloads As of 13/04/2023, if you only change method bodies the game will attempt a much faster hotload. This should be most useful when tweaking code handling visuals or UI. Not all changes are supported to start with, so it might still have to fall back to the old slower hotload in some cases. If you start encountering errors that could be related to this feature, you can disable it with this console variable: ``` hotload_fast 0 ``` Please also tell us about what went wrong in an issue here: https://github.com/sboxgame/issues/issues It'll be super helpful to know what change you made when the problem occurred. Also please make sure to check if anyone else has already made an issue!
S&box Wiki
Development
Developer Overview
6
Editor Overview
General FAQ
System Requirements
The s&box wiki
Troubleshooting
Useful Links
The Project System
4
Adding Assets
Creating a Game Project
Project Settings Window - Games
Project Types
Publishing To Asset Party
2
Uploading assets
Uploading projects
Hammer
Getting Started With Hammer
3
Getting Started With Hammer
Making Your First Map
Mapping Resources
Mapping Basics
7
Cordons
Hotspot Materials
Selection Sets
Standard Mapping Dimensions
Tool Materials
Tools Visualisation Modes
Using Entities That Require a Mesh
Mapping Entities
2
Creating a Door
Light Entities
Advanced Mapping Techniques
8
Collaborating With Prefabs and Git
Instances
Prefabs
Quixel Bridge Plugin
Tilesets
Tilesets-Advanced
Tilesets-Proxies
VIS Optimizations
Models & Animation
Getting Started with Modeldoc
7
Automatic Model Setup
Breakpieces
Creating a Model
Guide to Models
Importing Rust Weapons
LODs
ModelDoc FAQ & best practices
Animgraph & Animation
4
Animations without Animgraph
AnimEvents, AnimGraph Tags, Attachments
Animgraph
Delta Animations
Physics
3
Cloth Physics
Collisions, Physics & Surface Types
Jiggle Bones
Modeldoc Nodes
1
Custom ModelDoc nodes
Advanced Modelling
6
Bodygroups
Citizen
First Person
IKChains and Stride Retargeting
Morphs
Vertex Normals
User Interface
UI Basics
7
Custom Fonts
Embedding Websites
Enabling Pointer Events
Events and Input
Localization
UI Basics
UI with Components
Styles & Stylesheets
1
Video Backgrounds
Razor Templates
4
A Razor Overview
Aliases and SetProperty Attributes
Generic Components
Templates
Game Menus
1
Making a Custom Pause Screen
Materials & Shaders
Materials
5
Guide to Materials
Material Attributes
Material Resources
Texture Settings
Using Dynamic Expressions
Built In Shaders
2
Foliage Shader
Glass Shader
Shaders
4
Compute Shaders
Constant Buffers
Material API
Shading Model
Shader Reference
5
Anatomy of Shader Files
Getting rid of Tex2D macros
Shader Reference
Shader States
Texture Format Cheat-Sheet
Other Assets
Sounds & Audio
3
Guide to Sounds
Sound Events
Soundscapes
Particles
5
Creating animated sprites
Creating your first particle effect
Understanding Particle Editor
Using custom sprites
Using particle systems from C#
Coding
Getting Started
5
Cheat Sheet
Learning Resources
Setting up Rider
Setting up Visual Studio
Setting up Visual Studio Code
Making Games
2
Components
GameObjects
Input
4
Commands
ConVars
Input System
Speech Recognition
Networking
7
Auth Tokens
Http Requests
Lobby System
Networked Types
Networking Basics
RPCs
WebSockets
Physics
5
Collisions
Hitboxes
Joints
Traces
Triggers
Rendering
3
Render Tags
RenderHooks
Scenes
Editor & Tools
7
Creating a Tool
Custom Asset Types
Guide to Widgets
Hammer API
Hammer Gizmos
Hotload Performance
Widget Docking
VR
3
Getting Started
VR Input
VR Overlays
Misc
13
Asset Types
Attributes and Component Properties
Backend API
Cloud Assets in code
Code Accesslist
CPU Performance Profiling
DisplayInfo
FileSystem
Mounting assets at runtime
package/find
Setting Up A Navigation Mesh
Threaded Tasks
TypeLibrary
Playing
Playing Guides
3
Default Keybinds
Proton
s&box on macOS (Experimental)
Console Commands & Variables
1
Launch Arguments
Dedicated Server
1
Dedicated Servers