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

Enable property functions for "fill-color" and "fill-outline-color" #2629

Merged
merged 7 commits into from
May 27, 2016

Conversation

lucaswoj
Copy link
Contributor

@lucaswoj lucaswoj commented May 26, 2016

}
}

});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an ideal long term architecture. I'm thinking on how to improve this...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could DRY up the code by something like this:

FillStyleLayer.prototype.fallbackMapping = {'fill-outline-color': 'fill-color'};

And then using this object to map properties in StyleLayer, avoiding code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sold on that design

  • Similar branching logic would still need to be written, but it'd be in StyleLayer rather than FillLayer
  • I can't think of many (any?) other style properties that have fallback behaviour like this

My preferred solution would be to factor out all the per-paint-property methods in StyleLayer into a StyleValue class (that might replace StyleDeclaration and/or StyleTransition)

type StyleValue<T> {
  isZoomConstant: boolean;
  isFeatureConstant: boolean;
  calculate(zoom:number, featureProperties: {}) => T;
  getInterpolationT(zoom: number) =>;
  ...
}

Then, FillStyleLayer's implementation would only have one overriden method:

getStyleValue: function(name) {
  if (name === 'fill-outline-color' && this.getPaintProperty('fill-outline-color') === undefined) {
    return StyleLayer.prototype.getStyleValue.call(this, 'fill-color');
  } else {
    return StyleLayer.prototype.getStyleValue.call(this, name);
  }
}

All that said, I'd be happy to 🚢 with the code in this PR for now. It may be verbose and non-DRY but it is clear, robust, and well-contained.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed refactor sounds great! Yeah, we can follow-up on that later. I'd make sure to run benchmarks before merging though because things like this make things slower if they're in hot path.

'fill',
bucket.paintAttributes.fill[layer.id].defines,
bucket.paintAttributes.fill[layer.id].vertexPragmas,
bucket.paintAttributes.fill[layer.id].fragmentPragmas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var attributes = bucket.paintAttributes.fill[layer.id];

@lucaswoj
Copy link
Contributor Author

Ready to 🚢 @jfirebaugh @mourner?

@jfirebaugh
Copy link
Contributor

I'm not caught up on gl-js buffer architecture so I don't think I can meaningfully review here.

@lucaswoj
Copy link
Contributor Author

Main thread perf seems to have taken a hit:

Benchmarks

Buffer

this branch: 854 ms
master: 827 ms

FPS

this branch: 48fps
master: 59 fps

Frame Duration

this branch: 19.7 ms per frame. 72% of frames took longer than 16ms.
master: 7.8 ms per frame. 0% of frames took longer than 16ms.

@mourner
Copy link
Member

mourner commented May 27, 2016

@lucaswoj whoa, 2.5x slower frame is a blocker for merging. I guess we'll have to refactor this.

@lucaswoj
Copy link
Contributor Author

@mourner the perf regression was due to a bug in createProgram. New numbers:

Benchmarks

Buffer

this branch: 809 ms
master: 827 ms

FPS

this branch: 60fps
master: 59 fps

Frame Duration

this branch: 9.7 ms per frame. 1% of frames took longer than 16ms.
master: 7.8 ms per frame. 0% of frames took longer than 16ms.

@mourner
Copy link
Member

mourner commented May 27, 2016

That looks much better. If you can't find a way to fight back that 2ms within a reasonable timeframe (say half an hour), let's 🚢 and figure out later.

@lucaswoj
Copy link
Contributor Author

@mourner I suspect that 2ms is just measurement error. I'll try to create a cleaner testing environment and see if the discrepancy goes away.

@lucaswoj
Copy link
Contributor Author

lucaswoj commented May 27, 2016

I was wrong -- the difference is definitely significant.

this branch

9.7 ms per frame. 1% of frames took longer than 16ms.
9.8 ms per frame. 3% of frames took longer than 16ms.
10.5 ms per frame. 3% of frames took longer than 16ms.

master

8.3 ms per frame. 0% of frames took longer than 16ms.
8.2 ms per frame. 2% of frames took longer than 16ms.
7.9 ms per frame. 0% of frames took longer than 16ms.

@lucaswoj
Copy link
Contributor Author

lucaswoj commented May 27, 2016

I got a smidgen of perf back by optimizing useProgram further. I suspect that the rest of the perf loss is due to moving this uniform setup inside a hotter loop.

This is something we can and should optimize later but will require some bigger architectural work.

@lucaswoj lucaswoj merged commit bd00d66 into master May 27, 2016
@lucaswoj lucaswoj deleted the dds-fill branch May 27, 2016 22:17
@mourner
Copy link
Member

mourner commented May 27, 2016

In context of frame performance, even 2ms is 20% difference. Let's make sure we don't loose track of this, maybe ticket?

@lucaswoj
Copy link
Contributor Author

➡️ #2640

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.

3 participants