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

Bug-analyzeCircuit() executes when simulation is disabled #967

Open
Taste62 opened this issue Nov 1, 2024 · 5 comments
Open

Bug-analyzeCircuit() executes when simulation is disabled #967

Taste62 opened this issue Nov 1, 2024 · 5 comments

Comments

@Taste62
Copy link

Taste62 commented Nov 1, 2024

Circuitjs executes analyzeCircuit() after every change in the layout, which makes it impossible to work on larger projects, even, if the simulation times afterwards are ok.

@pfalstad
Copy link
Collaborator

pfalstad commented Nov 1, 2024

could you send me an example of a large file that analyze circuit runs slowly on?

@Taste62
Copy link
Author

Taste62 commented Nov 2, 2024

I did some more testing and there seems to be more depth to this than I expected. anaylzeCircuit() takes 7800ms in LaggyCircuit1.circuitjs.txt, but when I load the subcircuit file it drops to 50ms. LaggyCircuit2.circuitjs.txt is just a long wire with a resistor and two labels on each end. In this file analyzeCircuit() takes around 16000ms, but when I put it into a subcircuit, it drops down to 0.2ms (see LaggyCircuit(2).circuitjs.txt).

@pfalstad
Copy link
Collaborator

pfalstad commented Nov 2, 2024

Yes, I tried a test circuit with a large number of wires chained together, and that was really slow because of the wires, but I wasn't sure how realistic that situation was. When you put it in a subcircuit the wires are removed so it's fast.

@Taste62
Copy link
Author

Taste62 commented Nov 2, 2024

How about LaggyCircuit1? Even, if it's expected to be so slow, it would help a lot, if it only analyzed the circuit when the simulation is running, so the circuit can be modified without waiting a few seconds every time something is moved.

@pfalstad
Copy link
Collaborator

pfalstad commented Nov 2, 2024

Yeah, it doesn't need to analyze the circuit when it's not running. So that would be an easy fix, I assume.

LaggyCircuit1 is slow because of findUnconnectedNodes(). The main loop is slow and has to be run ~20 times. I'm not sure we need to start over from scratch every time we find an unconnected node, so I may be able to speed that up. Also, finding connections between two nodes looks really slow for subcircuit elements. Maybe that could be speeded up or at least cache the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants