Skip to content

First frame takes a very long time to load if the DrawMode is swapped often #945

Description

@cyrgani

Example:

use macroquad::prelude::*;
use std::array;
use std::time::Instant;

#[macroquad::main("slow")]
async fn main() {
    let line_points: [Vec3; 2000] = array::from_fn(|_| {
        vec3(
            quad_rand::gen_range(0.0, screen_width()),
            quad_rand::gen_range(0.0, screen_height()),
            quad_rand::gen_range(0.0, 1.0),
        )
    });
    let squares: [Vec2; 1000] = array::from_fn(|_| {
        vec2(
            quad_rand::gen_range(0.0, screen_width()),
            quad_rand::gen_range(0.0, screen_height()),
        )
    });

    loop {
        clear_background(LIGHTGRAY);

        for i in 0..1000 {
            draw_line_3d(
                vec3(line_points[i].x, line_points[i].y, line_points[i].z),
                vec3(line_points[i + 1000].x, line_points[i + 1000].y, line_points[i + 1000].z),
                BLUE,
            );
            draw_poly(squares[i].x, squares[i].y, 4, 2.0, 0.0, RED);
        }

        let t = Instant::now();
        next_frame().await;
        println!("time for await: {:?}", t.elapsed());
    }
}

On the first run, this prints:

time for await: 570.241663ms
time for await: 6.083847ms
time for await: 13.534707ms
time for await: 16.068566ms
time for await: 16.863645ms
time for await: 15.514372ms
time for await: 16.550544ms
time for await: 16.419731ms
time for await: 16.5569ms
time for await: 15.814831ms

Running it several times in a row makes it faster, but the difference is still visible:

time for await: 49.537983ms
time for await: 8.848842ms
time for await: 16.459325ms
time for await: 16.368043ms
time for await: 16.36937ms
time for await: 16.45276ms
time for await: 16.418258ms
time for await: 16.520926ms
time for await: 16.394233ms

This is especially relevant because #943 adds a new DrawMode, which can then cause this slowness if we alternate between drawing a lot of polygons / lines and circles.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions