ScriptProfiler [Full Release]

Thank you for this update, Developers!

I’m getting some strange metrics from my parallel task module. I only recorded for about 10 seconds but got some unusually high CPU time from an executeModule function in my code.

Does anything in this function stand out as problematic?

local function executeModule(actor: TaskActor, target: ModuleScript, ...: any)
	local success, module: Module? = pcall(require, target)
	assert(success and typeof(module) == "table", "Error loading module while executing actor!")

	local thread = actor:GetAttribute("Thread")
	assert(thread, "No thread assigned while executing actor!")

	local worker = setmetatable({
		_module = module,
		_thread = thread,
		_finished = false,
		_taskActor = actor,
	}, Worker)

	local execute = module.Execute
	local update = module.Update

	local canUpdate = false
	local memCat = actor.Name

	if typeof(update) == "function" then
		local conn: RBXScriptConnection

		conn = RunService.Heartbeat:ConnectParallel(function(dt: number)
			if actor:GetAttribute("Thread") == thread then
				if not worker:IsFinished() then
					debug.setmemorycategory(memCat)
					update(worker, dt)
				end
			else
				-- Task has been cancelled.
				task.synchronize()
				conn:Disconnect()
				return
			end

			if worker:IsFinished() then
				-- Task has been finished.
				task.synchronize()
				conn:Disconnect()
			end
		end)

		canUpdate = true
	end

	-- Desync and call the worker's
	-- 'Execute' routine if it exists.
	task.desynchronize()

	if typeof(execute) == "function" then
		debug.setmemorycategory(memCat)
		execute(worker, ...)
	end

	-- Automatically finish if there's
	-- no 'Update' routine to loop on.

	if not canUpdate then
		worker:Finish()
	end
end

I have an uncopylocked place where I’m observing this available here:

1 Like

In my opinion, new sampling profiler is important. I will check it out :+1:

Correct me if im wrong but i have a feeling i’ve actually seen ScriptProfiler in the developer console ingame (not in roblox studio), though i never knew what it meant or what it’s purpose was because i don’t use the dev console that much

othervise, this update seems quite promising

I’ve been waiting for this for such a long time. Finally it’s coming out instead of looking at the Memory tab! :smiley:

1 Like

I like using the % metric.
Next to the start button you can change what Unit displays.

I can’t make much sense of the ms unit so I like % instead since it shows where most activity is going that would require optimizations.

Now that I’m experimenting with it more I have a question/request.

Is it possible to implement a toggle where the stats on ScriptProfile are displayed in realtime?
I think it’d be great to see a livefeed of spikes in activity, it could possibly help narrow down more complicated issues by being able to combine visual feedback of what’s going on in the game and seeing the live feed of % activity.

Hopefully it’s something that isn’t impossible.
But other than that, this tool is great in general I’ve been able to experiment with performance improvements in existing classes.

1 Like

Strongly agree on this as well

Going to be quite useful for debugging, I used to run external tools but this will be quite helpful.

1 Like

Are there any plans to allow saving profiles? This would be really helpful for comparing different profiles instead of having to open each branch and taking multiple screenshots.

I’ve been really enjoying this feature so far, keep up the good work!

This is an amazing change, that will really help scripters in general but mostly beginners. An expansion on this, as many here have requested already would be great. Real-time, LuaHeap memory specification etc.

Anyway, this already guided me to take a look at some of my used scripts and immediately helpful (for now in a small way, but still). Now just waiting for it to hit live servers!

Yes, that’s something that we have considered.

1 Like

Lovely! I’ve long been meaning to clean up messy CPU-eating scripts, and this is just what I needed (microprofiler was okay as it showed what exact scripts were using a lot of frame time, but it didn’t go into detail as to what part of those scripts were consumptive).

Wow, it made me realise how I have used mouse.hit so much that it’s tangibly causing large ms-wait times.

Something I also noticed is that a default roblox script (EmoteMenuMaster) is allegedly taking up 60% of performance… not sure what the implications of this are, but I did have the menu open as my mouse was locked in first person and had to free it to record the script performance debug.


Searching in studio led it to the Script Profiler module actually (I believe this is leftover data from the testing that is brought to studio, but searching it nearly crashed the program lol)

Is a release to live servers planned in the future? Or is that not intended?

Amazing update, this will be really useful for optimizing on lower end devices.

This is awesome! Would it be possible to let scripts access this data? It would be really cool to be able to send it to a service such as Sentry which now has analytics for performance aggregates. Alternatively, could this also be integrated into the Roblox developer stats page?

1 Like

Will this support flame graphs or other visual aids that don’t require spamclicking through tree views?

Hi Developers,

We are happy to announce ScriptProfiler has exited beta and is now available to everyone.

ScriptProfiler is a new sampling profiler that records the call-stacks of all executing scripts at a 1KHz frequency. This feature offers developers an additional optimization tool within DevConsole to debug performance issues and identify scripts using the most CPU resources.

For more information on using ScriptProfiler, please check out this article.

As of today, the ScriptProfiler tab within DevConsole is now available within both Studio and the Roblox Client. This release enables developers to profile Client and Server code on live experiences.

Please let us know if you have any questions or concerns.

Thank you.

6 Likes

Yes this would be very helpful, please!

Just wanted to say this has been really helpful, actual playing players is way better testing environment!