Replies: 21 comments 17 replies
-
I have another thought regarding the caching mechanism. |
Beta Was this translation helpful? Give feedback.
-
I think it's dead code. You said yourself that Group wasn't touched since 2014. Originally posted by @ShaMan123 in #7859 (comment) |
Beta Was this translation helpful? Give feedback.
-
so first an assertion. |
Beta Was this translation helpful? Give feedback.
-
So there are a bunch of points here that spin up interesting conversation and performance should be an afterthought in this case. Sometimes caching is required in order for things to work correctly, the example is the clipPath, if a group has a clipPath we can't avoid caching it, because we won't be able to cut away pixels in isolation if the objects are rendered already on the canvas context. Having many cache canvases slow down the browser at a certain point and make the library unusable on safari IOS. Absolute clippathnow absolute clippath was a quick thought. When adding clipPath i said, if i remove the transform before drawing it the clipPath will be applied in the canvas, solving what people were often trying to do, define a visibility area for an object in the canvas ( collages for example ). So taken by the enthusiasm i just thought it was cool and i added it. ShadowsShadows are slow. Shadows are different from browser to browser, but people use shadow for some effects. GlobalCompositeOperationIs years i want to fix it. It enables effects people are familiar with, caching broke it. Trying to answer Shachar points:
|
Beta Was this translation helpful? Give feedback.
-
Didn't understand what you meant.
I have worked around this in the eraser. It is possible to propagate the clip path to other caches |
Beta Was this translation helpful? Give feedback.
-
I wrote it bad. Why do you like the absolute positioned clipPath, what is the use case for which those are irreplaceable? |
Beta Was this translation helpful? Give feedback.
-
i m fine removing the deep check on cache invalidation if consistently using the set('dirty') keeps the things working. |
Beta Was this translation helpful? Give feedback.
-
I am experimenting with this approach Go to http://fabricjs.com/raphael-vs-fabric-simple?n=5000&optimize_caching=1 to test without layer caching vs.Raphael.Simple.Shape._.Fabric.js.Benchmarks.-.Google.Chrome.2022-04-07.17-31-28.mp4Originally posted by @ShaMan123 in #7860 (comment) |
Beta Was this translation helpful? Give feedback.
-
Hi @ShaMan123 @asturur, |
Beta Was this translation helpful? Give feedback.
-
@mattevans-dev |
Beta Was this translation helpful? Give feedback.
-
A client posed a question that made me think of an elegant solution for the following: Let's say we have a VERY BIG (big in size, not number of objects) object (maybe a group of objects) and we apply a clip path to it. How do we support this? Why don't we use the canvas' cache to render the object in 2 steps? |
Beta Was this translation helpful? Give feedback.
-
Global composite operation is broken since caching was introduced in 1.7 :( In practice global composite operation will work only from an object to its container. A group with darken will apply darken to all objects on the canvas drawn before it. This is also complicated because the SVG export will probably have an hard time keeping this working, but is one of the few ways we can enable global composite operation with consistency. Basically it will also enforce group caching when activated |
Beta Was this translation helpful? Give feedback.
-
Regarding the group and canvas caching, that is a delicate topic. I really don't want to embed multiple strategies in the library because different strategies will probably break other features. I really want to avoid feature creep in the library and i would also like to understand more about the cases in which a large group becomes too slow |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I want to see if I understand the issue with
I will add a POC |
Beta Was this translation helpful? Give feedback.
-
After adding the tests in #8271 I have to say it makes sense that gco acts only on the layer it is contained in. |
Beta Was this translation helpful? Give feedback.
-
I would like to present my rationale better. In fact it might be good to set |
Beta Was this translation helpful? Give feedback.
-
Another suggestion: |
Beta Was this translation helpful? Give feedback.
-
This diff shows the POC's output compared to the existing state where shadow isn't correct. The POC can be viewed here refactor-object-rendering...2step-caching |
Beta Was this translation helpful? Give feedback.
-
#8298 takes this discussion into a PR |
Beta Was this translation helpful? Give feedback.
-
@asturur
I have an idea how to refactor Group's caching mechanism.
Current Caveats:
absolutePositioned
clipPath
absolutePositioned
with objects nested in groups #7142shadow
Group With ClipPath and Text with Shadow Renders Incorrectly #7454V6
): Group Rewrite + Nested Selection #7669 (comment)To handle these caveats I suggest that group should never cache all objects but use a number of cache canvases that will update independently.
To handle caveats 1-4 we simply render these objects directly on group (because it won't cache, we render directly on canvas).
We shall need to handle group's clip path in such a case.
The rest of the static objects will be rendered to dedicated caches. Once an object is marked dirty it will mark the entire group as dirty and it's dedicated cache canvas.
If we add a flag to Object
perfWillUpdateFrequently
we can filter out animating objects as well.This should solve 1-4.
Regarding 5 I suggest we expose
batchingThreshold
or some prop that indicates the amount of static objects we want to batch into a single cache canvas in order to boost perf for huge groups.This should solve 5.
We can implement the same logic for canvas (for 3-5). I have experimented with this. It is very promising.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions