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

WebGL markers and rects reuse arrays and buffers #11343

Merged
merged 2 commits into from
Jun 20, 2021
Merged

WebGL markers and rects reuse arrays and buffers #11343

merged 2 commits into from
Jun 20, 2021

Conversation

ianthomas23
Copy link
Member

Improvements to performance of WebGL rect and marker glyphs by reusing rather than recreating Float32Array/Uint8Arrays and ReGL Buffer objects. Similar to PR #11277 that applied to line glyphs; together the two PRs close the 5th item of issue #11052. No change in functionality or tests.

There is a new TypeScript file webgl/buffer.ts which brings functionality that was in base.ts, regl_wrap.ts and webgl_utils.ts together into a number of WrapperBuffer classes that wrap ReGL Buffer objects (which in turn wrap WebGL buffer objects) and is a more elegant solution.

To demonstrate the performance of WebGL vs canvas, I have used a similar approach to #11277 of rendering a set of rects and using the chrome FPS counter whilst panning in small circular motions. Test code is

import numpy as np
np.random.seed(8417)
from bokeh.plotting import figure, curdoc, show

N = 10_000
backend = 'canvas'
#backend = 'webgl'

p = figure(width=800, height=800, output_backend=backend, title=backend, lod_threshold=None)
x = np.random.uniform(size=(N,))
y = np.random.uniform(size=(N,))
w = np.random.uniform(0.001, 0.003, size=(N,))
h = np.random.uniform(0.001, 0.003, size=(N,))
fc = np.random.randint(0, 0xffffffff, size=(N,), dtype=np.uint32)
lc = np.random.randint(0, 0xffffffff, size=(N,), dtype=np.uint32)
p.rect(x, y, width=w, height=h, fill_color=fc, line_color=lc)
show(p)

so each rect has a random width, height, line color and fill color. On my dev laptop with integrated graphics the FPS results are:
screenshot

Other performance improvements are possible and I'll get to them in due course.

@bryevdv
Copy link
Member

bryevdv commented Jun 15, 2021

@ianthomas23 this LGTM as far as my expertise goes. Should this be labeled ready?

cc @jrbourbeau just an FYI given the dashboard is in the 10-50k rects regime AFAIK

@ianthomas23
Copy link
Member Author

@bryevdv Yes it is ready now that CI has passed.

@bryevdv
Copy link
Member

bryevdv commented Jun 18, 2021

@ianthomas23 I see there are some line-specific webgl tests in integration/glyphs/line.ts would it be appropriate now to add similar tests in a rect.ts?

@ianthomas23
Copy link
Member Author

@bryevdv There is a rect test in integration/glyphs/webgl.ts that I added in a previous PR:

it("should support rect", async () => {

It tests all 3 backends (canvas, svg and webgl) so I agree that it is in the wrong place and should be in integration/glyphs/rect.ts instead, particular as that is where you looked for it. Do you want it added to this PR or in a new one?

@bryevdv
Copy link
Member

bryevdv commented Jun 18, 2021

Do you want it added to this PR or in a new one?

I'm fine with a follow-up issue to organize webgl tests, but leave it to you. Either way, PR is approved, so please merge yourself immediately, or after moving the tests, if you decide to move the tests here.

@ianthomas23
Copy link
Member Author

rect integration tests moved to new file integration/glyphs/rect.ts.

@ianthomas23 ianthomas23 merged commit a4b239c into bokeh:branch-2.4 Jun 20, 2021
@ianthomas23 ianthomas23 deleted the webgl_rect_marker_reuse_buffers branch June 20, 2021 19:31
@ianthomas23 ianthomas23 mentioned this pull request Jun 20, 2021
5 tasks
@bryevdv
Copy link
Member

bryevdv commented Jun 21, 2021

Thanks @ianthomas23 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants