raysan5/raylib

[rtextures] Texture loading and unloading with logging slowly kills FPS in WASM

ferasboulala opened this issue · 1 comments

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

LoadTextureFromImage and UnloadTexture with logging slows down as the program advances if compiled using Emscripten for WASM. The FPS slowly drops with time. The issue goes away if logging level is set to LOG_ERROR.

If this should be posted in Emscripten instead, let me know.

Environment

Sonoma 14.2.1

INFO: Initializing raylib 5.1-dev                                                                                                                                                 
INFO: Platform backend: DESKTOP (GLFW)                                                                                                                                            
INFO: Supported raylib modules:                                                          
INFO:     > rcore:..... loaded (mandatory)                                                                                                                                        
INFO:     > rlgl:...... loaded (mandatory)                                               
INFO:     > rshapes:... loaded (optional)                                                
INFO:     > rtextures:. loaded (optional)                                                
INFO:     > rtext:..... loaded (optional)                                                                                                                                         
INFO:     > rmodels:... loaded (optional)                                                
INFO:     > raudio:.... loaded (optional)                                                
INFO: DISPLAY: Device initialized successfully                                                                                                                                    
INFO:     > Display size: 1728 x 1117                                                    
INFO:     > Screen size:  1600 x 800                                                                                                                                              
INFO:     > Render size:  1600 x 800                                                     
INFO:     > Viewport offsets: 0, 0                                                       
INFO: GLAD: OpenGL extensions loaded successfully                                                                                                                                 
INFO: GL: Supported extensions count: 43                                                 
INFO: GL: OpenGL device information:                                                                                                                                              
INFO:     > Vendor:   Apple                                                              
INFO:     > Renderer: Apple M1 Max                                                                                                                                                
INFO:     > Version:  4.1 Metal - 88                                                     
INFO:     > GLSL:     4.10                                                               
INFO: GL: VAO extension detected, VAO functions loaded successfully                                                                                                               
INFO: GL: NPOT textures extension detected, full NPOT textures supported                 
INFO: GL: DXT compressed textures supported                                              
INFO: GLFW platform: Cocoa

Issue Screenshot

Here is a flamegraph in Firefox (WASM). Most of the time is taken by texture loading. One level down, you see it's printing. FPS slowly deteriorates in time. Starts high, goes as low as 1 FPS.
image

Code Example

    Image exploration = GenImageColor(800, 800, BLACK);
    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        Texture2D map_texture = LoadTextureFromImage(map);
        UnloadTecture(map_texture);
        EndDrawing();
    }

Temporary fix

Disable logging.

@ferasboulala It seems a very improbable and forced use case. I can't imagine a situation graphic driver gets overloaded that way. In any case, it does not seem that much can be done in raylib side. Probably a lower level issue.