Memory Profiler¶
Note
This page covers the Memory Profiler, which attributes Daslang heap use to the functions that caused it. For frame timings and the high-level memory graph, see Performance Monitoring. For per-function timings in the external daProfiler application, see daProfiler.
The Memory Profiler records how much of the Daslang heap each of your functions is responsible for, and presents it as a call tree in the Memory tab of the editor’s Profiler window.
Like the Daslang Profiler, it instruments every Daslang function call, so it costs a significant amount of frame time. Turn it on while you are investigating memory, and off again afterwards.
Using Editor Settings¶
In the editor toolbar, click the Profilers button
Under Memory Profiler, check Enable and click Apply
The game reloads with memory instrumentation enabled
Play the game, then open Window ▸ Profiler and select the Memory tab
The Enable / Disable button in the Memory tab does the same thing, so once the tab is open you can switch it without going back to the toolbar. Either way the game reloads.
Usage¶
The table shows one row per function, nested as a call tree: a row’s children are the functions it called. The same function reached through two different callers appears twice, once under each, so you can tell which call path is responsible.
Rows with children have an arrow; click it to collapse a subtree you are not interested in.
Siblings are ordered by total heap, largest first.
Clicking a column header sorts by that column and switches to a flat list. Tick Tree to go back to the call tree.
Only functions whose subtree touched the heap are listed, so the table stays much shorter than the full call tree.
Results accumulate across hot reloads, so editing a script and saving does not lose what you have collected. Stopping the game does not clear the table either — the last collected data stays on screen so you can read it. Starting the game again begins a new session: the table clears as soon as the new run records its first call.
Table columns¶
Function- the function nameHeap (total)- heap allocated by the function including everything it calledHeap (self)- heap allocated by the function itself, excluding what it calledStr (total)- string heap allocated by the function including everything it calledStr (self)- string heap allocated by the function itselfAlloc- total bytes allocated, ignoring anything freed again (deep profiling only)Freed- total bytes freed (deep profiling only)Calls- how many times the function was calledLocation- the script file and line the function is declared on
The four Heap and Str columns are net figures: a function that allocates 1 MB and frees 900 KB
reports 100 KB. A negative value means the function freed more than it allocated. Alloc and
Freed are gross figures, which is how you find a function that churns a lot of memory
without its total ever growing. A free is credited to the function that allocated the memory, so a
block released somewhere else still shows up under the function responsible for it.
Paths in the Location column use Daslang’s short form, which also tells you where the code came
from: %file/ is your project, the script you launched included, %engine/ and
%privateScripts/ are EdenSpark, and %daslib/ is the Daslang standard library.
Note
A Daslang exception caught inside a recursive call leaves one stack entry behind, because the unwound frame and the returning one share a function identity. Calls recorded afterwards are attributed one level too deep for the rest of the session.
Note
The garbage collector does not report the objects it reclaims, so Freed stays low for
garbage-collected strings and arrays and fills in only for explicit frees such as delete.
The Heap columns are measured from the heap size before and after each call, so a function
that happens to span a collection reports less than it allocated, or even a negative figure.
Controls¶
Pause / Resume - stop and restart attribution of new allocations. A free of an allocation recorded before the pause still lands in
Freedand in the per-site balances, so those numbers can move across a pause. What is already collected stays on screen. Pausing does not make the game faster: the instrumentation still runs on every call. Disable the memory profiler to get that frame time back.Clear - discard everything collected so far. Starting a new run clears it as well.
Tree - switch between the call tree and a flat, sortable list. On by default; sorting the table by a column switches to the flat list.
Deep - enable deep profiling (see below). Off by default.
Dump tree to log - write the whole table to the log file, with per-allocation detail when deep profiling is on.
Dump globals to log - list the largest Daslang global variables, the same as the
gc.print_heap_usageconsole command. This works whether or not the profiler is running.Enable / Disable - turn the profiler on or off. Reloads the game.
Recording, clearing and dumping are also available as app.mem_profiler_*
console commands.
Deep profiling¶
The Deep checkbox hooks every individual allocation rather than only measuring the heap before and after each call. It adds two things:
The
AllocandFreedcolumns are filled in.Dump tree to log gains a per-allocation breakdown under each function, naming the exact line that allocated:
churn alloc 958244 freed 0 %file/main.das:5 -string 957860 bytes - %file/main.das:7:23
Here
churnis declared on line 5, and the allocation itself happened at line 7, column 23.
Deep profiling costs extra on every allocation, so it is off by default and the net Heap
columns work without it. The toggle applies to the running game; no reload is needed.
Because a switched-off hook cannot observe frees, the per-site balances collected before the gap
cannot be trusted afterwards; turning Deep back on therefore starts them over. The Heap,
Alloc, Freed and Calls columns keep accumulating across the gap.