Skip to content

Commit b96318c

Browse files
committed
Greatly optimized scrolling performance by setting a max log length for logs that aren't expanded. By default, it's 200 characters.
1 parent 2c8a74d commit b96318c

3 files changed

Lines changed: 58 additions & 31 deletions

File tree

Plugins/IngameDebugConsole/IngameDebugConsole.prefab

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ MonoBehaviour:
868868
logcatArguments:
869869
avoidScreenCutout: 1
870870
popupAvoidsScreenCutout: 0
871-
maxLogLength: 10000
871+
maxCollapsedLogLength: 200
872+
maxExpandedLogLength: 10000
872873
autoFocusOnCommandInputField: 1
873874
logItemPrefab: {fileID: 11408050, guid: 391be5df5ef62f345bb76a1051c04da7, type: 3}
874875
commandSuggestionPrefab: {fileID: 6838696818539158795, guid: 5e66896448428cf46a1854dbdc014914,
@@ -3470,7 +3471,7 @@ MonoBehaviour:
34703471
m_faceColor:
34713472
serializedVersion: 2
34723473
rgba: 4294967295
3473-
m_fontSize: 12.3
3474+
m_fontSize: 16
34743475
m_fontSizeBase: 36
34753476
m_fontWeight: 400
34763477
m_enableAutoSizing: 1
@@ -4095,7 +4096,7 @@ MonoBehaviour:
40954096
m_faceColor:
40964097
serializedVersion: 2
40974098
rgba: 4294967295
4098-
m_fontSize: 3.5
4099+
m_fontSize: 16
40994100
m_fontSizeBase: 36
41004101
m_fontWeight: 400
41014102
m_enableAutoSizing: 1

Plugins/IngameDebugConsole/Scripts/DebugLogItem.cs

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ public void Initialize( DebugLogRecycledListView listView )
6969
logTextOriginalSize = logText.rectTransform.sizeDelta;
7070
copyLogButtonHeight = ( copyLogButton.transform as RectTransform ).anchoredPosition.y + ( copyLogButton.transform as RectTransform ).sizeDelta.y + 2f; // 2f: space between text and button
7171

72-
logText.maxVisibleCharacters = listView.manager.maxLogLength;
73-
7472
copyLogButton.onClick.AddListener( CopyLog );
7573
#if !UNITY_EDITOR && UNITY_WEBGL
7674
copyLogButton.gameObject.AddComponent<DebugLogItemCopyWebGL>().Initialize( this );
@@ -141,29 +139,47 @@ public void UpdateTimestamp( DebugLogEntryTimestamp timestamp )
141139
SetText( logEntry, timestamp, isExpanded );
142140
}
143141

144-
private void SetText( DebugLogEntry logEntry, DebugLogEntryTimestamp? logEntryTimestamp, bool isExpanded )
145-
{
146-
if( !logEntryTimestamp.HasValue || ( !isExpanded && !listView.manager.alwaysDisplayTimestamps ) )
147-
logText.text = isExpanded ? logEntry.ToString() : logEntry.logString;
148-
else
149-
{
150-
StringBuilder sb = listView.manager.sharedStringBuilder;
151-
sb.Length = 0;
152-
153-
if( isExpanded )
154-
{
155-
logEntryTimestamp.Value.AppendFullTimestamp( sb );
156-
sb.Append( ": " ).Append( logEntry.ToString() );
157-
}
158-
else
159-
{
160-
logEntryTimestamp.Value.AppendTime( sb );
161-
sb.Append( " " ).Append( logEntry.logString );
162-
}
163-
164-
logText.text = sb.ToString();
165-
}
166-
}
142+
private void SetText(DebugLogEntry logEntry, DebugLogEntryTimestamp? logEntryTimestamp, bool isExpanded)
143+
{
144+
string text = isExpanded ? logEntry.ToString() : logEntry.logString;
145+
int maxLogLength = isExpanded ? listView.manager.maxExpandedLogLength : listView.manager.maxCollapsedLogLength;
146+
147+
if (!logEntryTimestamp.HasValue || (!isExpanded && !listView.manager.alwaysDisplayTimestamps))
148+
{
149+
if (text.Length <= maxLogLength)
150+
logText.text = text;
151+
else
152+
{
153+
if (listView.manager.textBuffer.Length < maxLogLength)
154+
listView.manager.textBuffer = new char[maxLogLength];
155+
156+
text.CopyTo(0, listView.manager.textBuffer, 0, maxLogLength);
157+
logText.SetText(listView.manager.textBuffer, 0, maxLogLength);
158+
}
159+
}
160+
else
161+
{
162+
StringBuilder sb = listView.manager.sharedStringBuilder;
163+
sb.Length = 0;
164+
165+
if (isExpanded)
166+
{
167+
logEntryTimestamp.Value.AppendFullTimestamp(sb);
168+
sb.Append(": ").Append(text, 0, Mathf.Min(text.Length, maxLogLength - sb.Length));
169+
}
170+
else
171+
{
172+
logEntryTimestamp.Value.AppendTime(sb);
173+
sb.Append(" ").Append(text, 0, Mathf.Min(text.Length, maxLogLength - sb.Length));
174+
}
175+
176+
if (listView.manager.textBuffer.Length < sb.Length)
177+
listView.manager.textBuffer = new char[sb.Length];
178+
179+
sb.CopyTo(0, listView.manager.textBuffer, 0, sb.Length);
180+
logText.SetText(listView.manager.textBuffer, 0, sb.Length);
181+
}
182+
}
167183

168184
// This log item is clicked, show the debug entry's stack trace
169185
public void OnPointerClick( PointerEventData eventData )

Plugins/IngameDebugConsole/Scripts/DebugLogManager.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,13 @@ public class DebugLogManager : MonoBehaviour
199199
[Tooltip( "If enabled, on Android and iOS devices with notch screens, the console window's popup won't be obscured by the screen cutouts" )]
200200
internal bool popupAvoidsScreenCutout = false;
201201

202-
[SerializeField]
203-
[Tooltip( "If a log is longer than this limit, it will be truncated. This helps avoid reaching Unity's 65000 vertex limit for UI canvases" )]
204-
internal int maxLogLength = 10000;
202+
[SerializeField]
203+
[Tooltip("If a log that isn't expanded is longer than this limit, it will be truncated. This greatly optimizes scrolling speed of collapsed logs if their log messages are long.")]
204+
internal int maxCollapsedLogLength = 200;
205+
206+
[SerializeField, UnityEngine.Serialization.FormerlySerializedAs("maxLogLength")]
207+
[Tooltip("If an expanded log is longer than this limit, it will be truncated. This optimizes scrolling speed while an expanded log is visible.")]
208+
internal int maxExpandedLogLength = 10000;
205209

206210
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL
207211
[SerializeField]
@@ -407,6 +411,12 @@ public bool PopupEnabled
407411
// StringBuilder used by various functions
408412
internal StringBuilder sharedStringBuilder;
409413

414+
/// <summary>
415+
/// Used for <see cref="TMP_Text.SetText(char[])"/>.
416+
/// </summary>
417+
[System.NonSerialized]
418+
internal char[] textBuffer = new char[4096];
419+
410420
// Offset of DateTime.Now from DateTime.UtcNow
411421
private System.TimeSpan localTimeUtcOffset;
412422

0 commit comments

Comments
 (0)