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.

Possible performance problem with UnmodifiableConfig

See original GitHub issue

I was analysing my Minecraft setup with JFR to find mods that were misbehaving. One of the hottest methods from outside Vanilla came from LambDynamicLights. (In the JFR recording, I just stood still and looked around my base.)

The hot method is Arrays.copyOf(Object[], int) which is responsible for > 1% of all CPU cycles. The stack trace leading to this is:

java.util.Arrays.copyOf()
[JDK internal stuff]
java.util.ArrayList.add()
dev.lambdaurora.lambdynlights.shadow.nightconfig.core.utils.StringUtils.split()
dev.lambdaurora.lambdynlights.shadow.nightconfig.core.UnmodifiableConfig.getOrElse()

which is called from dev.lambdaurora.lambdynlights.DynamicLightsConfig.hasEntitiesLightSource() and dev.lambdaurora.lambdynlights.DynamicLightsConfig.hasBlockEntitiesLightSource(), respectively.

I have not dived into the the source code yet, but by the name of the class, it sounds like getting an “Unmodifiable Config” should not really have to do a string split (which ends up doing array copies) each time it is called. I imagine there is some easy room for improvement here.

Let me know if you want me to submit a PR with a fix. (I suspect a developer familiar with the code can make it quicker than I, but I’m willing to help if there is not enough resources on the project.)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
LambdAuroracommented, Sep 26, 2021

Let me know if you want me to submit a PR with a fix. (I suspect a developer familiar with the code can make it quicker than I, but I’m willing to help if there is not enough resources on the project.)

Very sorry but while reading I totally missed this part, feel free to PR, I’m not currently much available so any help is appreciated.

0reactions
magicuscommented, Nov 10, 2021

Fixed by commit 2678e56a2fc63531f2d9d9f59dfafdab7217f88e.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any performance benefit of using an unmodifiable list ...
I would think that an unmodifiable list is more efficient, because we know that the items in the list won't change, so maybe...
Read more >
java - Returning Unmodifiable Collections only tees you up for ...
Returning Unmodifiable Collections only tees you up for runtime exceptions? Yes and no. Yes, it does do that. No, it doesn't only do...
Read more >
Improving Performance with Cache-Control: immutable
The following two examples show how you can implement the Cache-Control: immutable directive in either Apache or Nginx.
Read more >
How to Fix the Unsupported Operation Exception in Java
The UnsupportedOperationException can be resolved by using a mutable collection, such as ArrayList , which can be modified. An unmodifiable ...
Read more >
Optimizing Performance - React
If you're benchmarking or experiencing performance problems in your React apps, make sure you're testing with the minified production build.
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