Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General performance and memory usage improvements #316

Merged
merged 31 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6f7bd51
Replace AsyncTask with Async and do some code cleanup
ammarasyad Dec 17, 2023
9681020
Use only one executor for async tasks
ammarasyad Dec 17, 2023
3e53393
Add null safety in SettingsMenu
ammarasyad Dec 17, 2023
92445a0
Use empty array instead of pre-sized in toArray() calls
ammarasyad Dec 17, 2023
5a8b489
Use built-in arraycopy rather than manually copying
ammarasyad Dec 17, 2023
c353c48
Use StringBuilder instead of string concatenation in loops, fix MD5Ca…
ammarasyad Dec 17, 2023
3a403f6
Use String.isEmpty() instead of String.equals()
ammarasyad Dec 17, 2023
6441b0a
Use try-with-resources and some code cleanup
ammarasyad Dec 17, 2023
dcc4488
Fix some textures not being unloaded
ammarasyad Dec 17, 2023
1e281e9
Convert inner classes to static
ammarasyad Dec 17, 2023
ae1aea3
Performance improvements and code cleanup (assisted by IDEA Code Insp…
ammarasyad Dec 17, 2023
4c0d03c
Fix integer division in floating-point context
ammarasyad Dec 17, 2023
8d9f29c
Fix implicit lossy cast and metronome volume
ammarasyad Dec 17, 2023
b47ec7d
Update async executor pool name
ammarasyad Dec 17, 2023
a3c00d6
Revert Comparator changes for compatibility
ammarasyad Dec 17, 2023
f2fe75a
Refactor MainScene
ammarasyad Dec 17, 2023
44081da
Revert Objects.requireNonNullElse call for compatibility
ammarasyad Dec 18, 2023
58e5bb8
Convert ChimuWebView and DownloadingFragment to Kotlin
ammarasyad Dec 18, 2023
263825d
Fix resource string conversion
ammarasyad Dec 18, 2023
50a34c1
Delete unnecessary and unused things
ammarasyad Dec 18, 2023
e11d2b9
Refactor and cleanup ResourceManager
ammarasyad Dec 18, 2023
05a39a5
Lazy load multiplayer related fragments
ammarasyad Dec 25, 2023
aee954f
Remove unnecessary FilterMenu class and use FilterMenuFragment (Kotli…
ammarasyad Dec 26, 2023
5563191
Remove GC calls
ammarasyad Dec 26, 2023
f402e8e
Fix possible fragment memory leak, save required fields to static class
ammarasyad Dec 26, 2023
81ddfbc
Fix InGameSettingMenu memory leak, Kotlin rewrite, revamp its fragmen…
ammarasyad Dec 26, 2023
b624d80
Fix custom difficulty value rounding and change speed modify toggle b…
ammarasyad Dec 26, 2023
c919089
Remove comment and initialize RoomChat in RoomScene in constructor
ammarasyad Dec 26, 2023
33b85b8
Tidy `InGameSettingMenu` further
Rian8337 Jan 21, 2024
409d00c
Fix isSettingPanelShow returning true if findViewById returns null
ammarasyad Jan 21, 2024
8fc248b
Add missing MD5 return in `MD5Calculator`
Rian8337 Jan 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion AndEngine/src/org/anddev/andengine/opengl/font/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public synchronized void update(final GL10 pGL) {
bitmap.recycle();
}
lettersPendingToBeDrawnToTexture.clear();
System.gc();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ public synchronized void updateTextures(final GL10 pGL) {
texturesManaged.remove(textureToBeUnloaded);
}
}

/* Finally invoke the GC if anything has changed. */
if(texturesToBeLoadedCount > 0 || texturesToBeUnloadedCount > 0){
System.gc();
}
}

// ===========================================================
Expand Down
2 changes: 1 addition & 1 deletion AndEngine/src/org/anddev/andengine/util/path/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public int getToTileColumn() {
// Inner and Anonymous Classes
// ===========================================================

public class Step {
public static class Step {
// ===========================================================
// Constants
// ===========================================================
Expand Down
10 changes: 4 additions & 6 deletions src/com/dgsrz/bancho/security/SecurityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static void getAppSignature(Context context, String packageName) {
return;
}
PackageManager pkgMgr = context.getPackageManager();
PackageInfo info = null;
PackageInfo info;
Signature[] signatures;

try {
Expand All @@ -90,22 +90,20 @@ public static void getAppSignature(Context context, String packageName) {
info = pkgMgr.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES);
SigningInfo signInfo = info.signingInfo;

if(signInfo.hasMultipleSigners()) {
if (signInfo.hasMultipleSigners()) {
signatures = signInfo.getApkContentsSigners();
appSignature = getHashCode(signatures[0].toByteArray());
}else {
signatures = signInfo.getSigningCertificateHistory();
appSignature = getHashCode(signatures[0].toByteArray());
}
appSignature = getHashCode(signatures[0].toByteArray());
}else {
info = pkgMgr.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
if(info != null && info.signatures != null && info.signatures.length > 0) {
Signature sign = info.signatures[0];
appSignature = getHashCode(sign.toByteArray());
}
}
} catch (PackageManager.NameNotFoundException e) {
return;
} catch (PackageManager.NameNotFoundException ignored) {
}
}

Expand Down
1 change: 0 additions & 1 deletion src/com/dgsrz/bancho/ui/StoryBoardTestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public Scene onLoadScene() {
BassAudioPlayer.initDevice();

try {
System.gc();
OsbParser.instance.parse(FOLDER + PATH);
} catch (IOException e) {
e.printStackTrace();
Expand Down
4 changes: 1 addition & 3 deletions src/com/edlplan/favorite/FavoriteLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public void save() {
object.put(entry.getKey(), array);
}
cover(object.toString(2), json);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/com/edlplan/framework/support/batch/BatchEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BatchEngine {

public static GL10 pGL;
public static ShaderGlobals shaderGlobals = new ShaderGlobals();
private static AbstractBatch savedbatch = null;
private static AbstractBatch<?> savedbatch = null;
private static boolean flushing = false;

public static ShaderGlobals getShaderGlobals() {
Expand Down Expand Up @@ -38,12 +38,12 @@ public static void setGlobalCamera(Camera camera) {
shaderGlobals.camera.set(camera);
}

static void bind(AbstractBatch batch) {
static <T> void bind(AbstractBatch<T> batch) {
flush();
savedbatch = batch;
}

static void unbind(AbstractBatch batch) {
static <T> void unbind(AbstractBatch<T> batch) {
if (savedbatch == batch) {
savedbatch = null;
}
Expand All @@ -58,7 +58,7 @@ public static void flush() {
}
}

public static AbstractBatch currentBatch() {
public static AbstractBatch<?> currentBatch() {
return savedbatch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void initialWithTextureListWithScale(List<TextureRegion> textures, float
switchTexture(0);
}

public class TextureEntry {
public static class TextureEntry {

public Vec2 size = new Vec2();

Expand Down
4 changes: 2 additions & 2 deletions src/com/edlplan/framework/support/graphics/BlendProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.edlplan.framework.support.batch.BatchEngine;
import com.edlplan.framework.utils.interfaces.Copyable;

public class BlendProperty implements Copyable {
public class BlendProperty implements Copyable<BlendProperty> {

public boolean enable = true;

Expand Down Expand Up @@ -61,7 +61,7 @@ public boolean equals(Object obj) {
}

@Override
public Copyable copy() {
public BlendProperty copy() {
return new BlendProperty(this);
}
}
4 changes: 2 additions & 2 deletions src/com/edlplan/framework/support/graphics/CanvasData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.edlplan.framework.utils.interfaces.Copyable;
import com.edlplan.framework.utils.interfaces.Recycleable;

public class CanvasData implements Recycleable, Copyable {
public class CanvasData implements Recycleable, Copyable<CanvasData> {

private float width;

Expand Down Expand Up @@ -153,7 +153,7 @@ public void recycle() {
}

@Override
public Copyable copy() {
public CanvasData copy() {
return new CanvasData(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void packAll(Iterator<String> collection, Consumer<Bitmap> onPackDrawDone
testAddRaw(t);
}

Collections.sort(infos, (p1, p2) -> Integer.compare(p1.pageIndex, p2.pageIndex));
Collections.sort(infos, (a, b) -> Integer.compare(a.pageIndex, b.pageIndex));

ListIterator<TextureInfo> iterator = infos.listIterator();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.edlplan.framework.support.osb;

import com.edlplan.edlosbsupport.command.SpriteCommand;
import com.edlplan.edlosbsupport.command.Target;
import com.edlplan.edlosbsupport.player.CommandBooleanHandleTimeline;
import com.edlplan.edlosbsupport.player.CommandColor4HandleTimeline;
Expand Down
8 changes: 2 additions & 6 deletions src/com/edlplan/framework/support/osb/StoryboardSprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ private void loadFromCache() {
}
});

Tracker.createTmpNode("LoadPlayer").wrap(() -> {
osbPlayer.loadStoryboard(storyboard);
}).then(System.out::println);
Tracker.createTmpNode("LoadPlayer").wrap(() -> osbPlayer.loadStoryboard(storyboard)).then(System.out::println);
}

public void loadStoryboard(String osuFile) {
Expand Down Expand Up @@ -255,9 +253,7 @@ public void loadStoryboard(String osuFile) {
}
});

Tracker.createTmpNode("LoadPlayer").wrap(() -> {
osbPlayer.loadStoryboard(storyboard);
}).then(System.out::println);
Tracker.createTmpNode("LoadPlayer").wrap(() -> osbPlayer.loadStoryboard(storyboard)).then(System.out::println);

}

Expand Down
4 changes: 2 additions & 2 deletions src/com/edlplan/framework/support/timing/RunnableHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RunnableHandler extends Loopable implements IRunnableHandler {
private Loopable.Flag flag = Loopable.Flag.Run;

public RunnableHandler() {
bufferedRunnables = new SafeList<DelayedRunnable>();
bufferedRunnables = new SafeList<>();
}

@Override
Expand Down Expand Up @@ -69,7 +69,7 @@ public Loopable.Flag getFlag() {
return flag;
}

private class DelayedRunnable {
private static class DelayedRunnable {
public Runnable r;
public double delay;

Expand Down
21 changes: 11 additions & 10 deletions src/com/edlplan/framework/support/util/Tracker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.edlplan.framework.support.util;

import androidx.annotation.NonNull;

import com.edlplan.framework.support.Framework;
import com.edlplan.framework.utils.advance.ConsumerContainer;
import com.edlplan.framework.utils.interfaces.Consumer;
Expand Down Expand Up @@ -28,8 +30,8 @@ public class Tracker {


static {
nodes = new ArrayList<TrackNode>();
namemap = new HashMap<String, TrackNode>();
nodes = new ArrayList<>();
namemap = new HashMap<>();

DrawArray = register(DRAW_ARRAY);
PrepareVertexData = register(PREPARE_VERTEX_DATA);
Expand Down Expand Up @@ -63,7 +65,7 @@ public static void printlnAsTime(int ms) {
}

public static Consumer<Integer> printByTag(String tag) {
return t -> System.out.println(String.format("[%s] %dms", tag, t));
return t -> System.out.printf("[%s] %dms%n", tag, t);
}

public static class TrackNode {
Expand Down Expand Up @@ -121,16 +123,15 @@ public ConsumerContainer<TrackNode> wrap(Runnable runnable) {
return new ConsumerContainer<>(this);
}

@NonNull
@Override
public String toString() {

StringBuilder sb = new StringBuilder();
sb.append("------------------------------------\n");
sb.append("name : " + name + " (" + id + ")\n");
sb.append("totalTime : " + totalTimeMS + "ms\n");
sb.append("trackedTimes : " + trackedTimes + "\n");
sb.append("------------------------------------");
return sb.toString();
return "------------------------------------\n" +
"name : " + name + " (" + id + ")\n" +
"totalTime : " + totalTimeMS + "ms\n" +
"trackedTimes : " + trackedTimes + "\n" +
"------------------------------------";
}
}
}
2 changes: 1 addition & 1 deletion src/com/edlplan/osu/support/object/StdSliderPathMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<Vec2> calculateSubPath(List<Vec2> subPoints) {

public LinePath calculatePath() {
path.clear();
List<Vec2> subControlPoints = new ArrayList<Vec2>();
List<Vec2> subControlPoints = new ArrayList<>();
for (int i = 0; i < getControlPoint().size(); i++) {
subControlPoints.add(getControlPoint().get(i));
if (i == getControlPoint().size() - 1 || getControlPoint().get(i).equals(getControlPoint().get(i + 1))) {
Expand Down
1 change: 0 additions & 1 deletion src/com/edlplan/osu/support/slider/DrawLinePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public DrawLinePath(AbstractPath p, float width) {

public DrawLinePath() {
alpha = 1;
this.width = width;
}

public DrawLinePath reset(AbstractPath p, float width) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/edlplan/osu/support/slider/SliderBody2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class SliderBody2D extends AbstractSliderBody {

private static final ThreadLocal<BuildCache> localCache = new ThreadLocal<BuildCache>() {
private static final ThreadLocal<BuildCache> localCache = new ThreadLocal<>() {
@Override
public BuildCache get() {
BuildCache cache = super.get();
Expand Down
17 changes: 8 additions & 9 deletions src/com/edlplan/osu/support/timing/TimingPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ public void setKiaiMode(boolean kiaiMode) {
@Override
public String toString() {

StringBuilder sb = new StringBuilder();
sb.append(getTime()).append(",");
sb.append(getBeatLength()).append(",");
sb.append(getMeter()).append(",");
sb.append(getSampleType()).append(",");
sb.append(getSampleSet()).append(",");
sb.append(U.toVString(isInherited())).append(",");
sb.append(((isKiaiMode()) ? 1 : 0) + ((isOmitFirstBarSignature()) ? 8 : 0));
return sb.toString();
String sb = getTime() + "," +
getBeatLength() + "," +
getMeter() + "," +
getSampleType() + "," +
getSampleSet() + "," +
U.toVString(isInherited()) + "," +
(((isKiaiMode()) ? 1 : 0) + ((isOmitFirstBarSignature()) ? 8 : 0));
return sb;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

public class ControlPoints {
private final ArrayList<TimingControlPoint> timingPoints = new ArrayList<>();
Expand Down Expand Up @@ -171,9 +173,9 @@ public DifficultyControlPoint getDifficultyPointAt(double time) {
DifficultyControlPoint difficultyControlPoint = binarySearch(difficultyPoints, time, defaultDifficultyPoint);
if (difficultyControlPoint == null) {
return defaultDifficultyPoint;
} else {
return difficultyControlPoint;
}

return difficultyControlPoint;
}

private <T extends ControlPoint> T binarySearch(List<T> list, double time, T prePoint) {
Expand Down
39 changes: 20 additions & 19 deletions src/com/edlplan/replay/OsuDroidReplayPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@ public static void packTo(File file, OsuDroidReplay replay) throws Exception {
}

public static byte[] pack(OsuDroidReplay replay) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipOutputStream outputStream = new ZipOutputStream(byteArrayOutputStream);
//try {
outputStream.putNextEntry(new ZipEntry("entry.json"));
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipOutputStream outputStream = new ZipOutputStream(byteArrayOutputStream)){
outputStream.putNextEntry(new ZipEntry("entry.json"));

JSONObject entryJson = new JSONObject();
entryJson.put("version", 1);
entryJson.put("replaydata", replay.toJSON());
JSONObject entryJson = new JSONObject();
entryJson.put("version", 1);
entryJson.put("replaydata", replay.toJSON());

outputStream.write(entryJson.toString(2).getBytes());
outputStream.write(entryJson.toString(2).getBytes());

outputStream.putNextEntry(new ZipEntry(replay.getReplayFileName()));
outputStream.putNextEntry(new ZipEntry(replay.getReplayFileName()));

File file = replay.isAbsoluteReplay() ?
new File(replay.getReplayFile()) : new File(OdrConfig.getScoreDir(), replay.getReplayFileName());
FileInputStream inputStream = new FileInputStream(file);
File file = replay.isAbsoluteReplay() ?
new File(replay.getReplayFile()) : new File(OdrConfig.getScoreDir(), replay.getReplayFileName());

byte[] buffer = new byte[1024];
int l;
while ((l = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, l);
}
try (FileInputStream inputStream = new FileInputStream(file)) {
byte[] buffer = new byte[1024];
int l;
while ((l = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, l);
}
}

outputStream.finish();
return byteArrayOutputStream.toByteArray();
outputStream.finish();
return byteArrayOutputStream.toByteArray();
}
}

public static ReplayEntry unpack(InputStream raw) throws IOException, JSONException {
Expand Down
Loading
Loading