Is my JavaScript code bad to JavaScript/CPU performance? [closed]

Posted on

Problem

I’m very worried about memory usage in JavaScript. I don’t have troubles with what I do, but I’m not sure if I did something as well :/ !

Most of the functions are for looping arrays (I stopped using prototype since I had to do something without using this (array)) with callback function.

What should IMPROVE from my code below?

_A0=//Array additions
_A1=//Media/Canvas/Audio additions
_A2=//Browser support detectors
{};

//end

//Array additions:

//Gen. functions example: Array[], [Argument 2]

_A0._0=function(_C0,_C1,_C2){//loop, 0 to len
    //arg 1. Array to loop
    //arg 2. Callback function (must break loop if _C2 is true and if returns false/null)
    //arg 3. Boolean (if true, arg 2. can return false to break looping)
    _C0._Ai=0,//i - saved in own Array's "_Ai" property
    _C0._Ab=_C0.length;//len - saved in own Array's "_Ab" property
    //this part that makes me very worried.
    //I'm not sure if I should do that.
    //I want to not create new adresses to memory, for the reason
    //I've saved the loop statics in Array's properties.
    //Is that bad?
    //If yeah, then what could I do?
    //JavaScript would be very heavy creating variables everytime.
    if(_C2){//loop with breaking
        for(;;){
            if(_C0._Ai==_C0._Ab)break;
            else if(!_C1(_C0._Ai))break;
            _C0._Ai++
        }
    }else{
        for(;;){
            if(_C0._Ai==_C0._Ab)break;
            _C1(_C0._Ai);
            _C0._Ai++
        }
    }
    _C0._Ab=_C0._Ai=null
},
_A0._1=function(_C3,_C4,_C5){//loop, len to 0
    _C3._Ac=_C3.length-1;//len
    if(_C5){//loop with breaking
        for(;;){
            if(_C3._Ac==-1)break;
            else if(!_C4(_C3._Ac))break;
            _C3._Ac--
        }
    }else{
        for(;;){
            if(_C3._Ac==-1)break;
            _C4(_C3._Ac);_C3._Ac--
        }
    }
    _C3._Ac=null
}

Solution

Don’t use obfuscated names. Use names that give an idea to readers what your code is supposed to do. As you can see from the comments, nobody has a clue what’s supposed to happen.

By the looks of it, you are trying to micro-optimise this code for “performance”. Trying to optimise code in this way is a terrible practice. Obfuscate and minify it when you are ready to deploy it to production if you must. Your development code can’t be written like this.

Leave a Reply

Your email address will not be published. Required fields are marked *