inconsistent speed with drawImage on the banglejs2

Posted on
  • hi, i've been rewriting the display algorithm for gipy and i'm running into performances issues.

    i used to render the lines directly on the screen but in the new algorithm lines are rendered into intermediate images (created with Graphics.createArrayBuffer).
    these images are then drawn on the screen with g.drawImage.

    the display time is now much better. displaying a full map takes on average 0.3s even in crowded areas.
    it is a huge speed increase and i'm quite happy about it.

    however there is an issue.
    usually a tile takes around 0.015 second to render.
    sadly sometimes a tile will suddenly take 1.2 second to draw.
    it is fully deterministic, i can reproduce it 100% of the time.
    in gipy's simulator i can follow the path and when i reach point 29 i meet my slow tile.
    however, if i don't follow the path but start directly at point 26 then when i follow from there and reach 29
    then the display is as fast as usual.
    this is very weird for me because it is the same tile in both cases and the display looks identical.

    any idea why drawImage could slow down 10x suddenly ?

  • Hi - what's your memory usage like?

    What can happen is that when memory gets a bit full it gets fragmented, and can no longer find a completely flat area of memory to allocate. Rather than crash it soldiers on, but because it hasn't got a flat area of memory it's a lot slower.

    Ideally, to fix it you'd try and allocate the buffers you need early on and keep them allocated, rather than freeing and re-allocating which is what you might be doing?

    But otherwise you can call E.defrag() which takes a while but will try and re-arrange things to get you a bigger area of free memory

  • hi, yes that should be it. the memory usage is very high.
    i think i should be able to allocate at start and reuse the buffers.
    i need to change a bit of code but it should be ok.

    thanks a lot! i'll give it a try this week end and post the result here

  • so a small message to confirm that you were right. reusing the buffers all performance issues disappear.

    thanks again for the tip.

  • Excellent! Thanks for letting me know :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

inconsistent speed with drawImage on the banglejs2

Posted by Avatar for wagnerf42 @wagnerf42