Skip to content

Commit

Permalink
A bunch of optimizations to load times
Browse files Browse the repository at this point in the history
Fix kotlin tests
Optimize imports in client package
Fix changelog displaying when swapping between windows and unix
- Don't load schematic browser repos on startup
- Further optimization to map preview loading
- Further optimizations to mod sprite packing
- Don't load changelog on startup
- Optimize KeyStorage & Signatures loading
  • Loading branch information
buthed010203 committed Apr 30, 2024
1 parent f6e8390 commit 6ddb132
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
23 changes: 23 additions & 0 deletions arc-core/src/arc/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,32 @@ public class Events{
private static class Handler<T>{ // FINISHME: Pool these maybe? I doubt it's needed though
private int id = ++lastId;
private final Cons<T> cons;
// private final String trace;

Handler(Cons<T> cons){
this.cons = cons;
// trace = null;
}

// Handler(Cons<T> cons, String trace){
// this.cons = cons;
// this.trace = trace;
// }
}

public static Class<?> debugType;

private static final ObjectMap<Object, Seq<Handler<?>>> events = new ObjectMap<>();

/** Handle an event by class. */
public static <T> void on(Class<T> type, Cons<T> listener){
String trace = null;
// if(type == debugType){
// StackTraceElement[] st = Thread.currentThread().getStackTrace();
// StringBuilder sb = new StringBuilder();
// for (int i = 2; i < st.length; i++) sb.append(st[i].toString()).append('\n');
// trace = sb.toString();
// }
events.get(type, () -> new Seq<>(Handler.class)).add(new Handler<>(listener));
}

Expand Down Expand Up @@ -78,17 +94,24 @@ public static <T> void fire(T type){

public static <T> void fire(Class<?> ctype, T type){
Seq<Handler<?>> listeners = events.get(ctype);
// boolean dbg = ctype == debugType;

if(listeners != null){
Iterator<Handler<T>> it = listeners.<Handler<T>>as().iterator();
// long tot = Time.nanos();
while(it.hasNext()){
Handler<T> listener = it.next();
if(listener.id == -1){
it.remove();
continue;
}
// long start = Time.nanos();
listener.cons.get(type);
// if (dbg) {
// Log.info("Event listener in @ms. Trace:\n@", Time.millisSinceNanos(start), listener.trace);
// }
}
// if (dbg) Log.info("Event fired in @ms", Time.millisSinceNanos(tot));
}
}

Expand Down
2 changes: 1 addition & 1 deletion arc-core/src/arc/graphics/g2d/TextureAtlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public PixmapRegion getPixmap(String name){
return getPixmap(find(name));
}

public PixmapRegion getPixmap(AtlasRegion region){
public PixmapRegion getPixmap(AtlasRegion region){ // FINISHME: Look into optimizing cases where we call the runnable below
if(region.pixmapRegion == null){
Pixmap pix = pixmaps.get(region.texture, () -> region.texture.getTextureData().getPixmap());
region.pixmapRegion = new PixmapRegion(pix, region.getX(), region.getY(), region.width, region.height);
Expand Down
62 changes: 61 additions & 1 deletion arc-core/src/arc/util/Threads.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.lang.ref.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;

/**
* Utilities for threaded programming.
Expand Down Expand Up @@ -42,8 +43,67 @@ public static void awaitAll(Seq<Future<?>> futures){
/** @return an executor with a fixed number of threads which do not expire
* @param threads the number of threads */
public static ExecutorService executor(@Nullable String name, int threads){
return Executors.newFixedThreadPool(threads, r -> newThread(r, name, true));
final AtomicInteger num = new AtomicInteger();
return Executors.newFixedThreadPool(threads, r -> newThread(r, threads == 1 ? name : name + "-" + num.incrementAndGet(), true));
}
// if (!"Main Executor".equals(name) || threads != OS.cores) return Executors.newFixedThreadPool(threads, r -> newThread(r, threads == 1 ? name : name + "-" + num.incrementAndGet(), true));
// return new ThreadPoolExecutor(threads, threads,
// 0L, TimeUnit.MILLISECONDS,
// new LinkedBlockingQueue<Runnable>(){
// @Override
// public void put(Runnable o) throws InterruptedException {
// super.put(o);
// queued.incrementAndGet();
// }
//
// @Override
// public boolean offer(Runnable o, long timeout, TimeUnit unit) throws InterruptedException {
// boolean r = super.offer(o, timeout, unit);
// if (r) queued.incrementAndGet();
// return r;
// }
//
// @Override
// public boolean offer(Runnable o) {
// boolean r = super.offer(o);
// if (r) queued.incrementAndGet();
// return r;
// }
// },
// r -> newThread(r, name + "-" + num.incrementAndGet(), true)) {
// @Override
// protected void afterExecute(Runnable r, Throwable t) {
// queued.decrementAndGet();
// done.incrementAndGet();
// }
// {
// daemon("Main Executor Watcher", () -> {
// startTime = Time.millis();
// while(true) {
// printStats(queued.get(), done.get());
// sleep(10);
// }
// });
// prestartAllCoreThreads();
// }
// };
// }
//
// private static final AtomicInteger queued = new AtomicInteger(), done = new AtomicInteger();
// private static long startTime, lastQ, lastD;
// private static void printStats(int numQueued, int numDone) {
// if (lastQ == numQueued && lastD == numDone) return;
// lastQ = numQueued;
// lastD = numDone;
// System.out.println(Strings.format("@q | @d | @t", numQueued, numDone, Time.timeSinceMillis(startTime)));
// }
//
// private static void getTrace() {
// StackTraceElement[] st = Thread.currentThread().getStackTrace();
// StringBuilder sb = new StringBuilder();
// for (int i = 3; i < st.length; i++) sb.append(st[i].toString()).append('\n');
// Log.info(sb.toString());
// }

/** @see #executor(String, int) */
public static ExecutorService executor(int threads){
Expand Down
1 change: 1 addition & 0 deletions extensions/packer/src/arc/packer/MaxRectsPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private Page packPage(Seq<Rect> inputRects){
if(!settings.silent){
if(++i % 70 == 0) System.out.println();
System.out.print(".");
System.out.flush();
}
bestWidthResult = getBest(bestWidthResult, result);
width = widthSearch.next(result == null);
Expand Down

0 comments on commit 6ddb132

Please sign in to comment.