Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

huge performance improvement suggestion #107

@charleyzhuyi

Description

@charleyzhuyi

After compared with different iOS chart libraries, BEMSimpleLineGraph is definitely the best one! After I integrated it on my own code, I found there may be fix can hugely improve the overall performance.

When I have more than 300 data point to be added to the lineChart, I found that it took more than 20 sec to load on my iphone 5, if 1500 data point, took more than 60 sec, and loading time seems growth exp.

After digger into the code for a while, i believe there may a issue:

In BEMSimpleLineraphView.m , drawDots method will loop through all the points and inside the loop, it calls dotValue method:

- (void)drawDots {
...
for (int i = 0; i < numberOfPoints; i++) { //first iterate 
    ...
    positionOnYAxis = [self yPositionForDotValue:dotValue];
    ...


- (CGFloat)yPositionForDotValue:(CGFloat)dotValue {
    CGFloat maxValue = [self maxValue]; // Biggest Y-axis value from all the points.
    CGFloat minValue = [self minValue]; // Smallest Y-axis value from all the points.
...

- (CGFloat)maxValue {
    if ([self.delegate respondsToSelector:@selector(maxValueForLineGraph:)]) {
        return [self.delegate maxValueForLineGraph:self];
    } else {
        ...
        for (int i = 0; i < numberOfPoints; i++) { //iterate again inside the loop
        ...

Inside, [self maxValue] or [self minValue] , it perform another loop for all the points again to find the min/max value in the points array if maxValueForLineGraph or minValueForLineGraph delegate is not implemented.

By implemented the optional maxValueForLineGraph and minValueForLineGraph (thus avoid auto calculate of min/max value), loading time for 1500 data point reduced from 60 sec to 0.8 sec.

My suggestion is to call [self maxValue] and [self minValue] only once in layoutSubview method and save it as a properties to be accessed in yPositionForDotValue method.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions