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

Performance Enhancements #29 - candle chart #192

Merged
merged 2 commits into from
Aug 27, 2015

Conversation

dorsoft
Copy link

@dorsoft dorsoft commented Jul 8, 2015

performance enhancement for the candle chart.

@danielgindi
Copy link
Collaborator

How exactly does this increase performance?
This actually makes the renderer loop over more labels than needed.
It also made scrolling jerkier when having 2.5K points

@dorsoft
Copy link
Author

dorsoft commented Jul 9, 2015

  1. I'd forgot to make the same change in drawDataSet(), I've pushed the fix to the PR. please pull and run the candle demo with 2500 candles.
  2. dataSet.entryIndex becomes slower as the chart is scrolled from left to right for datasets > 300.
    I've added time measurements logs and ran the candle demo with 2500 candles (iPhone 5) and scrolled the chart all the way to the right. I've found out that the 4 lines of code with dataSet.entryForXIndex and dataSet.entryIndex take about 70-90ms to complete and are called about 5-7 times a second i.e. (5 X 2 X 70ms) to (7 X 2 X 90ms) = 700ms to 1260ms per second are wasted.
  3. The render loops over the same number of labels and candles as:
    var entryFrom = dataSet.entryForXIndex(_minX)
    var entryTo = dataSet.entryForXIndex(_maxX)
    var minx = max(dataSet.entryIndex(entry: entryFrom!, isEqual: true), 0)
    var maxx = min(dataSet.entryIndex(entry: entryTo!, isEqual: true) + 1, entries.count)

is always equal to

var minx = max(_minX, 0)
var maxx = min(_maxX + 1, entries.count)

You can test this easily by adding some testing code like:

var minx2 = max(_minX, 0)
var maxx2 = min(_maxX + 1, entries.count)
if (maxx != maxx2 || minx != minx2) {
println("maxx2 or minx2 are different ! ! !")
}

@danielgindi
Copy link
Collaborator

This introduces only a very minor improvement, even for 2500. You have probably measured in an un-optimized compilation. Anyway, I've tested and did not find any side effects.

@danielgindi danielgindi merged commit 3865f54 into ChartsOrg:master Aug 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants