Skip to content

BitmapFrontEnd.hx, getUniqueKey performance #1965

Open
@Shinzo25

Description

  • Flixel version: 3.3.11
  • OpenFL version: 3.3.2
  • Lime version: 2.6.1
  • Affected targets: Android, Flash

Code snippet reproducing the issue:

public function getUniqueKey(?baseKey:String):String
{
    if (baseKey == null)
        baseKey = "pixels";

    if (checkCache(baseKey))
    {
        var inc:Int = 0;
        var ukey:String;
        do
        {
            ukey = baseKey + inc++;
        }
        while (checkCache(ukey));
        baseKey = ukey;
    }
    return baseKey;
}

I am making a puzzle game in which i am pre-creating 1024 FlxText objects.
Using Timer.stamp(), i was able to figure that each getUniqueKey in FlxText's new function holds around 0.002s, which means the 1024 takes around 2 seconds. It might not be that long but on android and on some low-end tablets, it can be very long.

I don't have a good understanding of how the internals of flixels work or what the next change will imply but here it goes :

public static var LatestInc:Int = 0;

public function getUniqueKey(baseKey:String = "pixels"):String
{
    if (checkCache(baseKey))
    {
        var inc:Int = LatestInc;
        var ukey:String;
        //ukey = baseKey + LatestInc++;
        do
        {
            ukey = baseKey + inc++;
        } while (checkCache(ukey));

        LatestInc = inc;

        baseKey = ukey;
    }
    return baseKey;
}

This gave me a 0.3s launch time.

I'm worried that internaly this affects something badly and i won't know it, thus me posting here.

First time posting on github, so...yeah, sorry for any problems or mistakes

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions