# Bug ID S-41: Graph Slowdown Bug

## Problem

When the matsuoka_et_al_2004/model.xml simulation runs, the graph cycles are displayed quickly to begin with, but gradually slow down over time.

## Solution

This model has seven graphs with X-axes of different lengths, but when simBio checks if repainting is needed, it checks only one graph before repainting all the graphs. Unnecessary repaints slow down the simulation. The solution is to check each graph and only repaint those which need to be repainted.

## Modified file list

• org.simBio.sim.analyzer.graph.Graph
• org.simBio.sim.analyzer.graph.Axis

## Code explanation

### org.simBio.sim.analyzer.graph.Graph

A call to the new method isRepaintNeeded() has been added to setAreaChanged(). If isRepaintNeeded() returns true, then the graph will be redrawn.

```public void setAreaChanged() {
if (isRepaintNeeded()){
super.setAreaChanged();
bufferRebuildFlag = true;
}
}
```

The isRepaintNeeded() method checks the X and Y axes of the graph for scale changes using the method isScaleChanged(), which has been added to the Axis class.

```private boolean isRepaintNeeded() {
if ( axisX.isScaleChanged() ) return true;
if ( axisY.isScaleChanged() ) return true;
return false;
}```

### org.simBio.sim.analyzer.graph.Axis

In the p method of Axis, which is called before setAreaChanged(), when the data is less than min or greater than max, then the scale is changed by a value of delta, which is added to minNode and maxNode.

```else {
// change scale
if (data < min) {
double delta = (min - max) * extendRate;
if ( this.extendMode == this.MODE_AUTOSCROLL ) {
}
} else {
// Data > max
double delta = (max - min) * extendRate;
if (this.extendMode == this.MODE_AUTOSCROLL) {
}
}
```

If the above code is executed, then the value of min no longer matches that of minNode (which has been changed by delta), and the value of max no longer matches that of maxNode. In this case, the new method isScaleChanged() returns true.

```boolean isScaleChanged() {
if (min != minNode.getValue() ) return true;
if (max != maxNode.getValue() ) return true;
return false;
}```

The values of min and max are then updated to those of minNode and maxNode when prepareRepaint() is called.

After the code changes above, the graphs in matsuoka_et_al_2004/model.xml are repainted only when necessary and so the simulation runs at a normal speed.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7005211,"math_prob":0.8508914,"size":2511,"snap":"2021-43-2021-49","text_gpt3_token_len":606,"char_repetition_ratio":0.1180694,"word_repetition_ratio":0.02917772,"special_character_ratio":0.23815213,"punctuation_ratio":0.1691974,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97809494,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-27T16:49:34Z\",\"WARC-Record-ID\":\"<urn:uuid:0618ddb5-9199-408b-983d-f98ad2efeb9f>\",\"Content-Length\":\"13983\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:317a4a2d-d8be-4e02-9a4b-1fd79eceb413>\",\"WARC-Concurrent-To\":\"<urn:uuid:346f55e2-ace8-4f3a-8137-241a7684f50c>\",\"WARC-IP-Address\":\"157.7.107.254\",\"WARC-Target-URI\":\"http://sim-bio.org/specification/bugs/s041.html\",\"WARC-Payload-Digest\":\"sha1:7IEIHU4FIBO2TWVCIVPTLPPOLNDBFOEZ\",\"WARC-Block-Digest\":\"sha1:R7FM5BDVNHQDWVN6EUJRFGQ3E2CDDXI2\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323588216.48_warc_CC-MAIN-20211027150823-20211027180823-00435.warc.gz\"}"}