question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sudden CPU spike when VertexArray reaches a certain size (1040)

See original GitHub issue

Issue details

Displaying a certain number of chars in a TextArea / TextField / Label (I’m suspecting pretty much everything than renders BitmapFonts?) on a stage, causes sudden increase in CPU usage. The exact number of chars differs depending on unknown circumstances (which font used perhaps?). In the test below, going from 33 to 34 chars in the TextArea (and again from 42 -> 43) causes huge increase in CPU usage. Only tested on desktop/windows. If you get this bug, but the number of chars needed to reproduce is different, please post how many.

Reproduction steps/code

import com.badlogic.gdx.*;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.*;

// Notice how CPU usage will spike at 34 chars, and then spike even further at 43

public class DesktopLauncher extends ApplicationAdapter {
    Stage stage;
    TextArea textArea;

    public void create () {
        stage = new Stage();
        Gdx.input.setInputProcessor(stage);
        Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
        textArea = new TextArea("TextArea test", skin);
        textArea.setWidth(400);
        textArea.setHeight(400);
        textArea.setPosition(40, 70);
        stage.addActor(textArea);

    }

    public void render () {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act();
        stage.draw();
    }

    public void resize (int width, int height) {
        stage.getViewport().update(width, height, true);
    }

    public static void main (String[] args) throws Exception {
        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        config.foregroundFPS = 0;
        config.vSyncEnabled = true;
        new LwjglApplication(new DesktopLauncher(), config);
    }
}

Version of LibGDX and/or relevant dependencies

Tested: 1.7.1 + 1.9.2

Please select the affected platforms

  • Android
  • iOS
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xoppacommented, Mar 10, 2016

Can reproduce the issue. Although, at least in my tests, it seems like the high cpu usage is not constant. E.g. the cpu usage might drop after a while to normal values. If I understand correctly, @Tom-Ski had some more constant results in reproducing it. I could not reproduce it on LWJGL3. With LwjglApplicationConfiguration#useGL30 set to true it seems like to always have a higher CPU (probably not related to this issue, see #3593 for details).

SpriteBatch uses VertexArray (when not gles3), using VBO instead seems one way to fix this issue. I think that SpriteBatch might use VA instead of VBO based on tests which might be somewhat outdated now that gles1 is no longer supported. Therefor I added a deprecated SpriteBatch.defaultVertexDataType member for easy testing the difference between the two.

Could you check whether, with latest nightly, adding the following line in your create method fixes it?

SpriteBatch.defaultVertexDataType = VertexDataType.VertexBufferObject;
0reactions
Tom-Skicommented, Apr 7, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

HOW TO TROUBLESHOOT SUDDEN CPU SPIKES? - GC easy
This type of sudden CPU spike usually happens because of two reasons: ... Once the application's memory usage hits the threshold point, ...
Read more >
Sudden CPU Spike 100% in windows server 2016 due to .Net ...
Hi All,. We have an issue in our production environment which is CPU suddenly spike to 100% and VM hangs/unresponsive mode and the...
Read more >
JAVA springboot API showing sudden increase in CPU ...
We have an API (JAVA springboot) that shows sudden increase in CPU consumption from less than 10% to 60-70% after a few minutes...
Read more >
How to Fix High CPU Usage - Intel
Find out all the reasons why your PC displays high CPU usage. Our step-by-step guide will show you how to fix your CPU...
Read more >
What are the Most Common Causes of CPU Spikes?
A CPU spike is a sudden increase in processor utilization, ... Some viruses automatically open multiple programs simultaneously; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found