Slower performance when running OF from Terminal

Hello guys,

So basically I’m having a slower performance (around 6-7 fps less on my computer - macpro i5 2015 16GB - and around 20 fps on a less powerful computer - macmini i5 2014 8GB- ) when I run an OF app from Terminal (by executing ./testApp inside /testApp.app/Contents/MacOS/ ) rather than by directly double-clicking on the .app file.
I need to run it from Terminal as the OF project will be launched by an sh script.

I simplified the project to make more understandable what Im doing (Wordcloud). So far it seems that this slow down comes from this line (in Word_Back::update):

ofVboMesh meshWord = _mesh_words_back.find(text)->second;

I’m aware that now I have the same word “test” but it also happens when I have different words with no repetition.

I will post here the scripts and also the zip file with the project if someone wants to compile it(no externals needed).

Word_Back.cpp

#include "Word_Back.h"

Word_Back::Word_Back(){}
Word_Back::~Word_Back(){}

//--------------------------------------------------------------
void Word_Back::setup(string _text, int _pos_x, int _pos_y, int _pos_z){
    
    text = _text;
    pos_x = _pos_x;
    pos_y = _pos_y;
    pos_z = _pos_z;
    
}

//--------------------------------------------------------------
void Word_Back::update(map<string,ofMesh> & _mesh_words_back, ofVboMesh & _meshWordsBack){
    
    ofVboMesh meshWord = _mesh_words_back.find(text)->second;
    vector<glm::vec3> & verticesWord = meshWord.getVertices();
    for(int i=0; i<meshWord.getVertices().size(); i++){
        meshWord.setVertex(i, verticesWord[i]+ofVec3f(pos_x, pos_y, pos_z));
    }
    _meshWordsBack.append(meshWord);
    
}

ofApp.h

#pragma once

#include "ofMain.h"
#include "Word_Back.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();    

        std::vector <Word_Back> words_back;
        map<string,ofMesh> mesh_words_back;
        ofVboMesh meshWordsBack;
    
        ofTrueTypeFont font;
        ofEasyCam cam;
		
};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    
    ofSetFullscreen(true);
    ofSetFrameRate(60);
    
    font.load("font.ttf", 100);

    int numberWords = 50000;
    
    for(int i = 0; i < numberWords; i++){
        
        int pos_x = ofRandom(-55000,55000);
        int pos_y = ofRandom(-35000,35000);
        int pos_z = ofRandom(-80000,80000);
        string _text = "test";
        
        Word_Back word_back;
        word_back.setup(_text, pos_x, pos_y, pos_z);
        words_back.push_back(word_back);
        
        ofVboMesh meshWord;
        meshWord = font.getStringMesh(_text,0,0,false);
        mesh_words_back.insert(make_pair(_text, meshWord));
        
    }
    
    cam.setFarClip(-2000);
    
}

//--------------------------------------------------------------
void ofApp::update(){
    
    for (Word_Back & word_back : words_back)
        word_back.update(mesh_words_back, meshWordsBack);
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    ofBackground(0);

    cam.begin();
    
    font.getFontTexture().bind();
    meshWordsBack.draw();
    font.getFontTexture().unbind();
    meshWordsBack.clear();
    
    cam.end();

    ofPushStyle();
    ofSetColor(0,255,0);
    ofDrawBitmapString(ofGetFrameRate(),20,20);
    ofDrawBitmapString(cam.getPosition(),20,40);
    ofPopStyle();
}

testKeystoneSlow.zip (110.8 KB)

Thanks in advance!
Joan

Can you try:
open testApp.app

From the terminal. This will open the app in the same way as double clicking on it in the Finder.

Hope that helps!
Theo

1 Like

thanks that works!! any idea why there’s a slow fps the other way?

I think the other way you are capturing all the output of the app in the terminal session.
If there are a lot of print outs, the output to terminal could be causing a slowdown.

Another way is:

./testApp.app/Contents/MacOS/testApp &

which says return immediately - but I think the open call is a better approach

if it it’s helpful you might experiment with nice command

which can set the priority of a command, you can say for example, launch the app with the highest priority (you may need to use sudo with nice) – in the past I’ve experimented with this when I’m calling OF from the command line…

thanks @zach !! I’ll try it soon :slight_smile: