Skip to content

GDExtension slower than GDscript #1063

@mbrlabs

Description

@mbrlabs

System: Manjaro Linux
Godot Version 4.0.0 stable
godot-cpp version: 9d1c396

I experimented a bit with GDExtension in Godot 4 and found that it is quite a bit slower than GDscript. Note that for this to work this needs to be merged first because of a bug.

Consider the following code in GDscript which modifies every pixel of an image. On my system this runs in about 20ms for a 512x512 image.

func test(img: Image) -> void:
    for x in img.get_width():
        for y in img.get_height():
	    var color := img.get_pixel(x, y)
	    color.r *= 1.5
	    img.set_pixel(x, y, color)

This GDExtension version takes 30ms, so 10ms longer (compiled with scons target=template_release):

void GDExampleTest::test(Ref<Image> img) {
    for (int x = 0; x < img->get_width(); x++) {
        for (int y = 0; y < img->get_height(); y++) {
            Color color = img->get_pixel(x, y);
            color.r *= 1.5;
            img->set_pixel(x, y, color);
        }
    }
}

I expected GDExtension to have a bit of overhead compared to normal modules when calling engine methods in a tight loop like that, but i did not think that it would be slower than even GDscript.

Not sure what to think here. Does this look normal to you? Basically the only reason i wanted to use GDExtension is to boost performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussiontopic:gdextensionThis relates to the new Godot 4 extension implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions