RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Debug DrawingGPU Mesh StructsImGui FFIMath Structs (FFI)FFI C DefinitionsPID ControllersCSV LibraryDelay LineDequeDevelopment UtilitiesEvent ReferenceExtension SystemSignal FiltersGraph PathfindingUI BridgeInput Filter Constants2D Bilinear InterpolationIntrospectionJBeam Pretty PrinterJSON AST ParserSJSON ParserJSON Debug ParserJSON Pretty PrinterK-D Tree (2D Boxes)K-D Tree (3D)K-D Tree (3D)Lua SerializerC++/Lua BindingLua CoreLua ProfilerMath LibraryParticlesQuadtreeSettingsTCP ServerTimer SchedulerUtility Library

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API Referencecommon

Lua Profiler

Module defined in `lua/common/luaProfiler.lua`. A Lua code profiler that measures execution time and garbage generation for code sections, with optional peak detection and smoothed statistics.

Module defined in lua/common/luaProfiler.lua. A Lua code profiler that measures execution time and garbage generation for code sections, with optional peak detection and smoothed statistics.


Exports

Global Functions

LuaProfiler(title)

Creates a new profiler instance.

  • Parameters:
    • title - string - Name for this profiler (shown in log output)
  • Returns: LuaProfiler - Profiler object

Instance Methods

profiler:start()

Begins a profiling frame. Call once per independent function being profiled.

profiler:add(section)

Marks the end of a code section and records its timing and garbage stats.

  • Parameters:
    • section - string - Name for this section (e.g., "physics stuff")

profiler:finish(compute, dt)

Ends the profiling frame and optionally logs results.

  • Parameters:
    • compute - boolean|nil - Set false to suppress all output (quick disable). Default: true.
    • dt - number|nil - When provided, enables peak detection mode - only logs when a performance spike is detected.

init()

Initializes the profiler, setting up hooks and data structures.

onUpdateGfx(dtSim, dtReal)

Called each graphics frame to update profiler display/data.

onUpdatePhysics(dtSim)

Called each physics step to update profiler timing data.

Metamethods

__index

Metatable index method for OOP-style method dispatch. Internal implementation detail.

Internal Notes

  • Uses HighPerfTimer (or hptimer) for microsecond-precision timing
  • Tracks garbage generation via collectgarbage("count") between sections
  • Statistics computed via newTemporalSmoothing (slow=0.5, fast=5) for averaging
  • Peak detection: triggers when the fast average deviates >50% from the slow average and the signal is stable (<10% instability)
  • Section-level peaks trigger at >30% deviation from average
  • Multiple add() calls to the same section name within a frame are aggregated (time summed, run count tracked)
  • Output format: bytes time_ms [vs avg_ms (+delta%)] section_name

See Also

  • cdefDebugDraw Reference - Related reference
  • cdefGpuMesh Reference - Related reference
  • cdefImgui Reference - Related reference
  • Common Libraries Overview - Guide

Lua Core

Module defined in `lua/common/luaCore.lua`. Adds core language features and polyfills used throughout the codebase - optional require, module reload, table utilities, and FFI initialization.

Math Library

Module defined in `lua/common/mathlib.lua`. Core math library providing `vec3` and `quat` types with operator overloading, plus extensive geometry utilities (ray intersections, OBB tests, splines, etc

On this page

ExportsGlobal FunctionsLuaProfiler(title)Instance Methodsprofiler:start()profiler:add(section)profiler:finish(compute, dt)init()onUpdateGfx(dtSim, dtReal)onUpdatePhysics(dtSim)Metamethods__indexInternal NotesSee Also