mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
add caching support to more component types
This commit is contained in:
@@ -41,4 +41,8 @@ public class Counter {
|
||||
public String toString() {
|
||||
return String.format("%dx %dms", count, TimeUnit.MILLISECONDS.convert(nanotime, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
|
||||
public String toAvgString() {
|
||||
return String.format("%dx %dms avg", count, TimeUnit.MILLISECONDS.convert(nanotime / count, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class DrawingCache {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void draw(IDIYComponent<?> component, G2DWrapper g2d, ComponentState componentState,
|
||||
boolean outlineMode, Project project, double zoom, boolean trackArea) {
|
||||
boolean outlineMode, Project project, double zoom) {
|
||||
ComponentType type = ComponentProcessor.getInstance()
|
||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
|
||||
@@ -69,7 +69,7 @@ public class DrawingCache {
|
||||
// only honor the cache if the component hasn't changed in the meantime
|
||||
if (value == null || !value.getComponent().equalsTo(component)
|
||||
|| value.getState() != componentState || value.getZoom() != zoom) {
|
||||
LOG.trace("Rendering " + component.getName() + " for cache.");
|
||||
// figure out size and placement of buffer image
|
||||
Rectangle2D rect = component.getCachingBounds();
|
||||
int width = (int)Math.round(rect.getWidth() * zoom);
|
||||
int height = (int)Math.round(rect.getHeight() * zoom);
|
||||
@@ -100,9 +100,6 @@ public class DrawingCache {
|
||||
|
||||
// initialize wrapper
|
||||
wrapper.startedDrawingComponent();
|
||||
if (!trackArea) {
|
||||
wrapper.stopTracking();
|
||||
}
|
||||
|
||||
long componentStart = System.nanoTime();
|
||||
|
||||
@@ -135,6 +132,10 @@ public class DrawingCache {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
if (wrapper.getCurrentArea() == null || wrapper.getCurrentArea().isEmpty()) {
|
||||
LOG.warn("Empty outline area detected for " + component.getName());
|
||||
}
|
||||
|
||||
// add to the cache
|
||||
value = new CacheValue(component, image, wrapper.getCurrentArea(), wrapper.getContinuityPositiveAreas(),
|
||||
wrapper.getContinuityNegativeAreas(), componentState, zoom, dx, dy);
|
||||
@@ -170,11 +171,13 @@ public class DrawingCache {
|
||||
stats.getSecond().add(componentEnd - componentStart);
|
||||
|
||||
// copy over tracking area from the cache
|
||||
g2d.merge(value.getCurrentArea(), value.getContinuityPositiveAreas(), value.getContinuityNegativeAreas());
|
||||
g2d.merge(value.getCurrentArea(), value.getContinuityPositiveAreas(), value.getContinuityNegativeAreas());
|
||||
} else {
|
||||
// no caching, just draw as usual
|
||||
component.draw(g2d, componentState, outlineMode, project, g2d);
|
||||
}
|
||||
g2d.stopTracking();
|
||||
g2d.stopTrackingContinuityArea();
|
||||
}
|
||||
|
||||
public void logStats() {
|
||||
|
||||
@@ -39,7 +39,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@@ -111,6 +110,7 @@ public class DrawingManager {
|
||||
private Map<String, Counter> renderStatsByType = new HashMap<String, Counter>();
|
||||
private long lastStatsReportedTime = System.currentTimeMillis();
|
||||
private long statReportFrequencyMs = 1000 * 60;
|
||||
private Counter totalStats = new Counter();
|
||||
|
||||
public DrawingManager(MessageDispatcher<EventType> messageDispatcher) {
|
||||
super();
|
||||
@@ -145,7 +145,7 @@ public class DrawingManager {
|
||||
IComponentFiler filter, Rectangle selectionRect, Collection<IDIYComponent<?>> selectedComponents,
|
||||
Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
||||
List<IDIYComponent<?>> componentSlot, boolean dragInProgress, Double externalZoom) {
|
||||
long start = System.nanoTime();
|
||||
long totalStartTime = System.nanoTime();
|
||||
failedComponents.clear();
|
||||
if (project == null) {
|
||||
return failedComponents;
|
||||
@@ -287,7 +287,7 @@ public class DrawingManager {
|
||||
try {
|
||||
|
||||
if (drawOptions.contains(DrawOption.ENABLE_CACHING)) // go through the DrawingCache
|
||||
DrawingCache.Instance.draw(component, g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, zoom, trackArea);
|
||||
DrawingCache.Instance.draw(component, g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, zoom);
|
||||
else // go stragiht to the wrapper
|
||||
component.draw(g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, g2dWrapper);
|
||||
|
||||
@@ -453,10 +453,9 @@ public class DrawingManager {
|
||||
g2d.fill(extraSpaceArea);
|
||||
}
|
||||
|
||||
long end = System.nanoTime();
|
||||
long totalEndTime = System.nanoTime();
|
||||
|
||||
long ms = TimeUnit.MILLISECONDS.convert(end - start, TimeUnit.NANOSECONDS);
|
||||
LOG.trace(String.format("Render time = %d ms", ms));
|
||||
totalStats.add(totalEndTime - totalStartTime);
|
||||
|
||||
logStats();
|
||||
|
||||
@@ -471,6 +470,7 @@ public class DrawingManager {
|
||||
.map(e -> e.toString())
|
||||
.collect(Collectors.joining("; ", "{", "}"));
|
||||
LOG.debug("Render stats: " + mapAsString);
|
||||
LOG.debug("Page stats: " + totalStats.toAvgString());
|
||||
DrawingCache.Instance.logStats();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2884,6 +2884,26 @@
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
<org.diylc.appframework.update.Version>
|
||||
<versionNumber>
|
||||
<major>4</major>
|
||||
<minor>3</minor>
|
||||
<build>0</build>
|
||||
</versionNumber>
|
||||
<releaseDate>2020-04-05 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added component-level caching that should speed up rendering dramatically. While in experimental phase, it will be exposed as "Enable Cache Boost" item in the "Config" menu so it can be turned off if it causes any issues</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Switched terminal on the "Open Jack 1/4" does not stick to other components</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
</a>
|
||||
</java.util.Arrays_-ArrayList>
|
||||
|
||||
Reference in New Issue
Block a user