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

WIP: A Patchable backend #89

Merged
merged 11 commits into from
Dec 16, 2014
Merged

WIP: A Patchable backend #89

merged 11 commits into from
Dec 16, 2014

Conversation

shashi
Copy link
Collaborator

@shashi shashi commented Nov 2, 2014

This back-end lets us draw Compose and Gadfly graphics using virtual-dom for rendering. There is a mechanism through which re-rendering happens via a diff-patch mechanism using Patchwork.jl: a set of patches is computed against the previously rendered SVG document and then applied.

This optimizes for network usage. And also allows for full-blown FRP-based GUI programming a la Elm and mercury using Julia+JavaScript.

Comments are welcome! I added draw_recursive to reduce the bookkeeping I had to do in the back-end if I were to use drawpart which seemed better for rendering by writing to a buffer, as opposed to rendering by constructing a data structure.

TODO

  • We want to allow JSCall, but loading gadfly.js and enabling zoom and pan features it provides can be disastrous for patching. A single element misplaced by JavaScript can cause the patching to behave unexpectedly. So we need a safer alternative. Panning is possible with viewBox. Zooming can also be implemented with viewBox, but will look weird. One good approach is to have Julia be involved in the zoom and pan process, I would love to zoom into a histogram and have the granularity increase as I do. This sort of a thing requires Julia intervention anyway. An extension of the idea is to have this behave like Google maps, i.e. initial zoom using viewBox, and then fetch patches from Julia to show more detail. I feel this item requires a more general widget creation mechanism to come from Patchwork or another package, so this probably should not block this PR.
  • Do not depend on Patchwork being installed - load this back-end only if Patchwork is present - this is in the interest of reducing load time.
  • Test rendering for all primitives. (Well I tried all the example plots on gadflyjl.org, I am hoping I can get away with that)
  • Text inside text elements should not be escaped while rendering

Patchwork issues

@StefanKarpinski
Copy link
Collaborator

Damn.

@StefanKarpinski
Copy link
Collaborator

Head explodes.

@dcjones
Copy link
Collaborator

dcjones commented Nov 3, 2014

This is really exciting!

I can see how the client-side pan/zoom implemented now may really difficult to reconcile. It gets pretty hairy since it applies a transformation then has to un-scale a bunch of geometry that should be scale invariant. I think it could be solved if, like you suggest, it called back to Julia on pan/zoom and gave it the option of re-rendering. So much good stuff we could do with that: dynamic bin sizes, recomputing label positions, contour plots that increase in resolution, plotting functions at increasing resolution, etc.

@shashi
Copy link
Collaborator Author

shashi commented Nov 4, 2014

OK I think this is ready to get merged, save naming improvements (Patchable...?) - suggestions are welcomed here. One question remains: What is the right way to allow the user to configure Compose to use Patchable? Time for a default_html_backend global? Right now, you can use Compose.patchable(plot(...)). Putting that inside @manipulate (given Pkg.checkout("IJulia", "master")) enables diff-patching.

Patchable outperformed (in terms of time taken) the SVG backend consistently for all plots I tried off of gadflyjl.org - except for the hexbin plot (which shares a lot of code with the SVG backend). Patchwork is particularly good with some kinds of graphics. An 8-level Sierpinski's triangle is 15x faster than the SVG backend. Note though that this timing didn't involve time required to generate JSON.

One more micro-benchmark: with 50 particles in the particles-in-a-box example described here - JuliaGizmos/Interact.jl#36 (comment) I got the following on htop

With SVG
normal

With Patchable
pw

Julia does seem to go easy on the CPU with Patchable. The GC pauses seem less pronounced, even non-existent.

cc @ViralBShah

@ViralBShah
Copy link
Collaborator

I think it would be nice to make Patchwork a default dependency of Compose, and given that it is pure Julia, it won't complicate things. @shashi just explained to me that there may be cases like pan-and-zoom where one may not want to use Patchwork as a default backend.

I think that the behaviour of Compose should not change in case Patchwork is installed, as it currently seems to be the case. Perhaps we can enable its use through the API.

@ViralBShah
Copy link
Collaborator

+1 to the idea of calling back Julia on events in the browser that would let us do a lot more interesting things. For example, doing interactive histograms over large datasets would become simple to implement. I think some of these recent capabilities are really putting us ahead of the pack. Really excited!

@ViralBShah
Copy link
Collaborator

Cc: @alanedelman

@shashi
Copy link
Collaborator Author

shashi commented Dec 16, 2014

Compose now imports Patchwork and Reactive if they are installed and defines a writemime for Signal{Context} objects using Patchwork. Merging.

shashi added a commit that referenced this pull request Dec 16, 2014
@shashi shashi merged commit 7cfec40 into GiovineItalia:master Dec 16, 2014
@ViralBShah
Copy link
Collaborator

👍

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.

4 participants