Using MicroProfiler

The MicroProfiler is an optimization tool available in Roblox Studio that helps developers improve performance by visually representing unoptimized portions of their experience. This tutorial will showcase how to use the MicroProfiler to identify problematic segments of your experience and use it to find the cause of the poor performance.

For a more hands-on look at this process, you can download the tutorial project file and follow along.

Starting MicroProfiler

MicroProfiler isn't visible by default and is summoned by keystroke. You can summon it any time, but it's most useful when an experience is running.

  1. Start by play testing your experience by pressing Play in the Home Menu.

  2. Summon MicroProfiler by pressing CtrlAltF6 (F6). You can see the render time for each individual frame represented at the top by the individual vertical orange bars. The higher the orange bar, the longer that particular frame takes to render.

Pausing MicroProfiler

MicroProfiler is constantly running, analyzing the render time for every frame. To see useful data, you need to pause MicroProfiler and analyze render information on a frame-by-frame basis. Press CtrlP to pause the MicroProfiler.

Each orange bar represents one frame, with the vertical height proportional to how long it takes that frame to render. You can tell something is wrong by how high the bars are. In the top right you'll see a green section that represents the current screen space. If you hover over the orange bars, you can select an individual frame for closer inspection.

On the left side of MicroProfiler, you'll see individual performance thread names. Click and drag down to find the largest horizontal category in that frame.

The horizontal length signifies the time duration this frame takes to render. A shorter horizontal length typically indicates well-optimized code. The vertical height is a hierarchy that signifies layers of code.

Identifying the Problem

Hovering your mouse over each section reveals information pertaining to that portion of code.

  1. Hover over RunService.Stepped and notice it takes about 26 milliseconds to render.

  2. Hover over LocalScript and notice that something is being called thousands of times.

    Continue down the list and notice the Raycast label. This indicates that the problem might be related to raycasting.

Creating Troubleshoot Labels

Now that MicroProfiler has provided a starting point, it's time to troubleshoot and review the code.

  1. Stop the play test and look at the LocalScript file to search for the problem.

    This portion of code appears to be the culprit for the experience's poor performance:


    local function onStepped()
    debug.profilebegin("RaycastSpam")
    for _ = 1, RAYS_PER_SECOND do
    local startPosition = getRandomPosition()
    local endPosition = getRandomPosition()
    local direction = endPosition - startPosition
    Workspace:Raycast(
    startPosition,
    endPosition
    )
    end
    debug.profileend()
    end

    Looking in our LocalScript in the RenderStepped event we see that there are rays being casted 1500 times per second. To make sure that this portion of code is indeed what's causing the rendering delay, give it a label that will highlight this portion of code when MicroProfiler is run.

  2. Create a label using the debug.profilebegin() tag and call it Raycast Spam.

  3. Close the tag by using debug.profileend().

Confirming the Problem

If the large horizontal bars in MicroProfiler are wrapped in this tag you will know that you were successful in identifying the unoptimized code.

  1. Playtest your experience.

  2. Pause MicroProfiler using CtrlP.

  3. Click and drag down to find the largest horizontal category in that frame.

  4. Look for the newly created Raycast Spam tag.