-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
test(): add event pointer caching failing test #9850
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Build Stats
|
src/canvas/SelectableCanvas.spec.ts
Outdated
expect(scenePoint).toEqual(new Point(50, 50)); | ||
expect(canvas.getScenePoint(e)).toEqual(new Point(50, 50)); | ||
canvas.setViewportTransform(createTranslateMatrix(50, 50)); | ||
// canvas._resetTransformEventData(); |
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.
uncomment this line and the test passes
d5c56b6
to
06f831c
Compare
the reason why those values were cached is because traversing the dom was expensive. Meaning that the actual point you click on the canvasElement the non scene one is not going to change, and that is the expensive one to calculate. Is non breaking anyway is just performances |
I ll say one more time, leaving comments in description of PRs like this one:
is not useful. |
This PR contains only a failing test, so i don't think we want to merge it. What is it for? |
To prove that we need to address it and to discuss. |
I do not think you will want to do that so I am forking |
My message is super clear, is there you can re-read it as many time as you want. I wrote you a bunch of messages with reminders of things said/planned but i don't think this is the place for it and then i felt like i was defending myself, thing i don't really need to do. You need a fork for how you want to work, but don't put it on me because is just not correct. I invited you a couple of months ago to fork because i noticed that they way you say you want to do things does not match the way you need to do things and you actually do things. |
Let me recap the professional side of our discussion. Why does fabric use event caching?
Why do I think fabric uses event caching?Fabric creates event context repeatedly when it fires events and uses that context in many cases. fabric.js/src/shapes/IText/ITextClickBehavior.ts Lines 246 to 247 in a055616
It seems that it is not used for historical reasons. The code was written and wasn't refactored to limit changes. My Approach: Fixing without Degrading PerformanceMy MotivationI prefer refactoring than workarounds. I hate gotchas and even more fabric gotchas. I want to fix this issue without degrading performance. A Different Design: context vs. cachingProviding context is the better way because: Fabric creates event context repeatedly when it fires events and uses that context in many cases.
Other Approach: Fix the Mentioned BugMotivationWe are at rc, maybe there is no option for refactors. Most likely no option for breaking changes. SuggestionsRemove caching
Though this sounds legit as a fix for the mentioned bug it doesn't fix other bugs caused by the same issue. Consider a RTL css layout app with the following case:
I do not want to degrade performance so removing caching entirely sounds bad if indeed the dom calculations are heavy. Assign the cached values to the DOM event itself
This is valid and does not break anything apart for a ton of tests. Posted in: #9853 |
A test in jest can be marked as |
Description
Caching pointers the way fabric does is bad design.
A very simple and common case will hit a severe bug.
Reproduce
From an event handler you need to change the viewport transform and then try to use
Canvas#getScenePoint
. That will return the cached value which is wrong.I added a simple test showing that.
In fact you would need to call
Canvas#_resetTransformEventData
to fixgetScenePoint
which doesn't make sense.If the perf opt is really that significant (and that is not clear) then we can assign the values to the pointer event so that e.scenePoint could be accessed instead of calling
getScenePoint
.This is also non breaking for rc. But I would say that these method are new anyways so no matter what the dev needs to visit them so we can say - if you wish to save on some computation replace canvas.getPointer with e.viewportPoint/e.scenePoint
Regardless, caching
Canvas#_target
has proved to be very limiting and hard to override by apps to a point that I am departing for all the event handlers and re implementing myself from scratch.In Action