Is draw api or server api better?

Godot Version

Above 4.2

Question

I’m pretty curious about which one is faster, the server api or draw. This example is basically what I’m thinking about:

# Draw API
func _process(delta: float) -> void:
	queue_redraw()

func _draw() -> void:
	for pos in pixels:
		draw_rect(Rect2(pos, Vector2.ONE), Color.WHITE)
# Server API
func _process(delta: float) -> void:
	var rid := get_canvas_item()
	RenderingServer.canvas_item_clear(rid)

	for pos in pixels:
		RenderingServer.canvas_item_add_rect(rid, Rect2(positions[i], Vector2.ONE), Color.WHITE)

You could put the code into a dedicated function and use the profiler to see how long to took to run.

My guess is that they will be the same. With the first version being slightly more efficient because it has one less parameter to handle in gdscript. But the second will probably be more direct on the native c++ side. So… Probably not much difference.

Yeah same as you, I did test them before with the profiler, and I barely see differences between them.