Repository: logisim-evolution/logisim-evolution (language: java)

Issue:
Redrawing of GUI-windows
One of the reasons for slow "simulation" is the fact that for each "change" in logisim the window redraw functions are called. This often leads to a snowball effect on redraw calls, and makes the whole program "slow".
I did not look into all details, but maybe there is a way to "catch" all these redraw requests and only do redraws for example 25 times/s. This should than increase speed and also have a more consistent "simulation feeling".


Discussion / hints:
Improving the simulation performance by limiting the number of redraws per second sounds promising!
I had thought of restricting the number of redraws a long while ago. But I didn't investigate it. My thought was to pick a prime number, p, such that with clock speed, c, c/p would be around 20-30. Then draw every p clock ticks. The use of a prime number was to make it unlikely that the circuit would sync with the redraw and never change the visual for changing values. But it might be easier to have another timer trigger the redraws and suppress the request with each clock tick.

It might also be useful to give the user control over the number of redraws per second. Perhaps 5 per second would be good enough for some uses.

Good idea.
I like @davidhutchens' idea of making the number of redraws per second user-configurable.
Hi,

I captured this video with AMD Driver on Windows 10 using Logisim. The clock speed was better than when I remade the project on Logisim Evolution (the first schematic ran above 2Khz, with Logisim Evolution I can barely achieve 120Hz, with the same set up).

https://www.youtube.com/watch?v=UP6tO8x5I5A

The schematic is authored by me and it is Open Source, just in case Logisim devs need it to help me achieve the max hertz speed on Logisim pro. 

https://github.com/ElijaxApps/Libre-8

Let's solve this issue please.
Thanks @crossplatformdev for your test case! I think we all agree that any improvement w.r.t. the simulation speed is very welcome, as are PRs in this area. Our bandwidth during the teaching term is unfortunately limited and we have to focus first on fixing bugs, which hamper our students' work.

Fix patch:
diff --git a/src/main/java/com/cburch/logisim/circuit/CircuitWires.java b/src/main/java/com/cburch/logisim/circuit/CircuitWires.java
index cde86732d2..6aa2393c96 100644
--- a/src/main/java/com/cburch/logisim/circuit/CircuitWires.java
+++ b/src/main/java/com/cburch/logisim/circuit/CircuitWires.java
@@ -181,7 +181,7 @@ private static Value pullValue(Value base, Value pullTo) {
   // derived data
   private Bounds bounds = Bounds.EMPTY_BOUNDS;
 
-  private BundleMap masterBundleMap = null;
+  private volatile BundleMap masterBundleMap = null;
 
   CircuitWires() {}
 
@@ -560,9 +560,10 @@ void draw(ComponentDrawContext context, Collection<Component> hidden) {
   // create the new bundle map.
 
   /*synchronized*/ private BundleMap getBundleMap() {
+    final var map = masterBundleMap;
+    if (map != null) return map;
     if (SwingUtilities.isEventDispatchThread()) {
       // AWT event thread.
-      if (masterBundleMap != null) return masterBundleMap;
       final var ret = new BundleMap();
       try {
         computeBundleMap(ret);
diff --git a/src/main/java/com/cburch/logisim/gui/main/Canvas.java b/src/main/java/com/cburch/logisim/gui/main/Canvas.java
index d753992438..3a70295130 100644
--- a/src/main/java/com/cburch/logisim/gui/main/Canvas.java
+++ b/src/main/java/com/cburch/logisim/gui/main/Canvas.java
@@ -1131,7 +1131,6 @@ public void selectionChanged(Selection.Event event) {
     @Override
     public void propagationCompleted(Simulator.Event e) {
       paintThread.requestRepaint();
-      if (e.didTick()) waitForRepaintDone();
     }
 
     @Override


Test patch: