-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fallbacks for IE9 #1297
Merged
Merged
fallbacks for IE9 #1297
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e81eca
fallbacks for ie9 are better than typedarray polyfill
alexcjohnson c0490d6
try adding 'ie9' tests
etpinard 4ce9df0
take 2 on ie9 test
etpinard 7cb691e
AJ proof ie9 bundle test
etpinard 2b1c0fe
Revert "try adding 'ie9' tests"
etpinard 675103c
Merge pull request #1299 from plotly/test-ie9
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
delete window.Promise; | ||
|
||
delete window.ArrayBuffer; | ||
delete window.Uint8Array; | ||
delete window.Float32Array; | ||
delete window.Float64Array; | ||
delete window.Int16Array; | ||
delete window.Int32Array; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var Plotly = require('@lib/core'); | ||
|
||
Plotly.register([ | ||
require('@lib/bar'), | ||
require('@lib/box'), | ||
require('@lib/heatmap'), | ||
require('@lib/histogram'), | ||
require('@lib/histogram2d'), | ||
require('@lib/histogram2dcontour'), | ||
require('@lib/pie'), | ||
require('@lib/contour'), | ||
require('@lib/scatterternary'), | ||
require('@lib/ohlc'), | ||
require('@lib/candlestick') | ||
]); | ||
|
||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
|
||
describe('Bundle with IE9 supported trace types:', function() { | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
it(' check that ie9_mock.js did its job', function() { | ||
expect(function() { return ArrayBuffer; }) | ||
.toThrow(new ReferenceError('ArrayBuffer is not defined')); | ||
expect(function() { return Uint8Array; }) | ||
.toThrow(new ReferenceError('Uint8Array is not defined')); | ||
}); | ||
|
||
it('heatmaps with smoothing should work', function(done) { | ||
var gd = createGraphDiv(); | ||
var data = [{ | ||
type: 'heatmap', | ||
z: [[1, 2, 3], [2, 1, 2]], | ||
zsmooth: 'best' | ||
}]; | ||
|
||
Plotly.plot(gd, data).then(done); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Can we polyfill this instead of relying on a slow
try-catch
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake. I jumped the 🔫 and didn't read your PR description.
try-catch
do that to me, I find them particularly irritating.Point taken. But, I'd call slowing down performance to support IE9 also unacceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you might say that... do we have data on how bad this issue is though? This is two
try
blocks per trace (which won't necessarily both fail together), no loops, is that really worrisome? Do you see a robust alternative?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick testing in Chrome and FF shows a negligible (~ns) impact of a
try
that does notcatch
, but a substantial impact (~µs) for atry
that fails and goes on tocatch
. Assuming similar behavior in other browsers, that would mean modern browsers (that do not need the fallback) will not be hindered, and those that DO need the fallback will be delayed by at most a few tens of µs.So I think we're OK here, but yeah, this clearly shows that
try/catch
should never be used within a loop, unless thecatch
will be exceedingly rare!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking!
I'm curious. Would a fallback be faster than
try-catch
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(new Uint8Array || new Array)(imageWidth * imageHeight * 4)
would fail most of the time in old browsers:typedarray
polyfill, thenUint8Array
is not just undefined, it's a bad symbol. I suppose we could get around that by sayingwindow.Uint8Array
but...imageWidth * imageHeight * 4 > 1e5
then theUint8Array
constructor will execute and throw an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I meant to write.
Good point here but .... what if we search for another polyfill that handles
> 1e5
arrays?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to really make something that behaves like a typed array, you need to add a whole lot of machinery, so no matter what you do it's going to be much slower than a bare array. That might be justified if you truly need to enforce the type restrictions, but we don't, we already have constructed our colors to be integers 0-255. So this overhead is simply harmful to us, far better to use a bare
Array
than any conceivable polyfill.So then the question is, is there ever a situation where we truly need the polyfill? Seems like no, right? Because any system that supports WebGL will already support typed arrays, and nothing else is affected by this.
And then I guess we could ask if there's a direct way to tell if we have real typed arrays vs polyfills. But honestly, I think based on my perf testing above, for the modern case - where we don't hit either of those
catch
blocks - this is actually the fastest possible code; short of doing the feature detection at compile time and completely swapping out theplot
routine 😱 we're not going to get less overhead than this. And for the fallback case we're only talking about a few tens of µs delay, hardly problematic for folks whose browsing experience is likely subject to far worse restrictions and bugs by now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I convinced me. 👍
But, we should agree on a way to test these
catch
blocks in #1299 before 💃 .