Overview of JEngine Hot Update Framework
# Source: https://github.com/JasonXuDeveloper/JEnginewebsite·Indexed 29 days ago
https://xgamedev.netA technical blog focusing on game development and C# programming. Topics include C# Source Generator performance profiling using MSBuildStructuredLog and JetBrains dotTrace, Roslyn, URP, 2D glow effects, and binary serialization.
# Source: https://github.com/JasonXuDeveloper/JEngineA collection of specialized C# libraries focusing on low-level optimization and systems architecture:
- Nino: https://github.com/JasonXuDeveloper/Nino
- Miku: https://github.com/JasonXuDeveloper/Miku
- EasyEcs: https://github.com/JasonXuDeveloper/EasyEcs# Source: https://github.com/JasonXuDeveloper/WriterTo prevent build slowdowns and improve the developer experience, apply the following optimization strategies to your Source Generators:
Span<char> and ReadOnlySpan<char> for slicing, StringBuilder for complex construction, and DefaultInterpolatedStringHandler for interpolation.for loops and batch file I/O operations or use in-memory alternatives.csc to compile a project that utilizes the target Source Generator and using JetBrains dotTrace to analyze the compilation process. This allows developers to see the execution time of individual functions within the Source Generator itself.After profiling the compilation process, use the following dotTrace views to identify bottlenecks in the Source Generator:
Focus on methods with high Total Time (including child calls) and high Own Time (time spent in the method itself), as well as expensive I/O operations or excessive string allocations.
Use MSBuildStructuredLog to retrieve the full command line arguments used by the C# compiler for a specific project:
msbuild.binlog file in MSBuildStructuredLog (File → Open Log File).csc in the left search box.These arguments include source files, referenced assemblies, Source Generator configurations, and compiler options.
Shader "Unlit/Fx"
{
Properties
{
_SrcTexture ("原图", 2D) = "clear" {}
_Rect ("图片信息", Vector) = (0, 0, 0, 0)
[Toggle(GLOW)] _GLOW ("发光", Float) = 0
_Color ("特效颜色", Vector) = (0, 0, 0, 0)
_Speed ("特效速度", Float) = 0
_Range ("特效范围", Float) = 0
_Alpha ("透明度", Range(0, 1)) = 1
[Enum(UnityEngine.Rendering.BlendMode)]_Src("_Src",Int)=5
[Enum(UnityEngine.Rendering.BlendMode)]_Dst("_Dst",Int)= 10
}
SubShader
{
Tags
{
"RenderType" = "Transparent"
"Queue" = "Transparent"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Blend [_Src][_Dst]
Pass
{
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float _Speed;
float _Range;
float _Alpha;
float4 _Rect;
float4 _SrcTexture_TexelSize;
float4 _Color;
CBUFFER_END
TEXTURE2D_FLOAT(_SrcTexture);
SAMPLER(sampler_SrcTexture);
#pragma vertex vert
#pragma fragment frag
struct Attributes
{
float4 positionOS : POSITION;
float4 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
};
Varyings vert(Attributes IN)
{
Varyings OUT;
OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
// Calculate UV based on _Rect (x, y, width, height)
float4 cur_pixel = float4(IN.uv.x * _Rect.z, IN.uv.y * _Rect.w, 0, 0);
float x = (_Rect.x + cur_pixel.x) * _SrcTexture_TexelSize.x;
float y = (_SrcTexture_TexelSize.w - _Rect.y - _Rect.w + cur_pixel.y) * _SrcTexture_TexelSize.y;
OUT.uv = float2(x, y);
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
half4 ret = SAMPLE_TEXTURE2D(_SrcTexture, sampler_SrcTexture, IN.uv.xy);
// Glow logic
half v = (cos(_Time.y * _Speed) + 1);
v = step(_Range, ret.a);
half4 c = _Color;
c.rgb *= v;
return ret; // Note: Final blending logic is continued in subsequent parts of the source
}
ENDHLSL
}
}
}csc to compile a project that utilizes the target Source Generator and using JetBrains dotTrace to analyze the compilation process. This approach allows developers to see the execution time of individual functions within the Source Generator itself to pinpoint specific performance issues.compile.rsp) in the project directory containing the .csproj file. This file must be saved with UTF-8 encoding. Paste only the compiler arguments starting from /noconfig through to the end of the command line./noconfig
/nowarn:1701,1702
/fullpaths
/define:DEBUG;TRACE
/reference:path/to/reference1.dll
/reference:path/to/reference2.dll
... (all other compiler arguments)Because compiler command line arguments are often too long for a standard shell command, they should be saved into a response file (.rsp).
From the extracted CommandLineArguments, identify the part starting from /noconfig to the end of the string. Save this specific segment into a text file with a .rsp extension. This file can then be passed to the compiler using the @ symbol.
# Example of the full command structure:
/usr/local/share/dotnet/dotnet exec "/usr/local/share/dotnet/sdk/9.0.303/Roslyn/bincore/csc.dll" /noconfig /unsafe- /checked- /nowarn:...
# The part to save in the .rsp file:
/noconfig /unsafe- /checked- /nowarn:...csc) to compile a project that utilizes the generator. By profiling this specific compilation process with JetBrains dotTrace, you can analyze the execution time of individual functions within the Source Generator itself.