-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Parallelize snap caching #31648
Parallelize snap caching #31648
Conversation
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!
I think there is other problems with my previous PR #31374. snapToCurrenLayer is always synchronous while snapToMap depends on the asynchronous parameter. Indeed, the idea of the PR was to make snapToMap in QGIS application asynchronous, so while the user move the cursor, the snap cache is built, and the snapping information are displayed as soon as they are built. But, it can be possible that people wants to use the snapToMap method synchronously in the application (like in PR #31613 for instance), and that won't work. I'm considering 3 possibilities:
|
Patching just snapToCurrentLayer seems a bit ad-hoc and as you say, there may be problems with other methods as well (including the ones in QgsPointLocator). I would suggest to keep the original API calls (snapToMap, snapToCurrentLayer etc) all synchronous, and introduce new methods with a new naming (e.g. snapToMapRelaxed?) that would be allowed to return invalid results if the index is being built... Then we would just modify some places to use the "relaxed" version so that this choice / optimization is always deliberate. A new variant of those functions compared to addition of a new true/false flag is IMHO a better indication that some special behavior is requested... |
@wonder-sk Thank you for your advices. I agree with your comments and will quickly propose a rewrite of my code to provide a snapToMap and snapToMapRelaxed methods. I propose to not share the asynchronous and synchronous locators, so snapToMap will deal with its own synchronous locators map and snapToMapRelaxed with its asynchronous locators map. |
3e2a17a
to
1043a6c
Compare
I added a snapToMapRelaxed method and also a boolean to get asynchronous point locators (needed in qgsvertextools). I use this method for maptools which provides some snapping information feedback and let the other use the classic snapToMap method. |
@wonder-sk any opinion here? |
The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check
|
Please don't stale |
@troopa81 3.10 is in hard freeze now and we've still got many open bugs relating to snapping due to this work not being complete/merged in time. Can you please open a pr reverting the earlier work for 3.10.0 asap so that we can get master back in release-ready state? |
@nyalldawson I would rather fix bugs you are mentionning than postponed this work. I take a quick look on qgis issues, and fail to find other issues related to this work. There is, if I recall correctly, 5 map tools that are currently broken and that PR should fix these. Is there other issues I'm not aware of? Most important thing I think is to agree on the API, because we won't change it after hard freeze. @wonder-sk did you have the time to check API changes? Anyway, if there is too much issues or complexity related to this work, I will revert my commit but again, I would prefer not to. |
@troopa81 About your proposed API changes, could you confirm what should be approved. I see it sums up to these two changes:
Is there something else ? |
@mhugo there is also the new method QgsSnappingUtils::snapToMapRelaxed() But this PR is the following of this one #31374 Actually the API changes bring by this work (the 2 PR) is:
|
Oops sorry everyone - my notifications to this PR got lost in my mail among 500+ other unread qgis notifications :-( Going to have a look... |
Hmm I am not sure I understand why we need to have separately synchronous and asynchronous locators... Could you please explain the reasoning? I am worried that this just adds extra memory+CPU overhead and higher code complexity without an obvious reason. I would expect to have just a single locator for each layer - if the locator is being indexed in the background and there's a call to non-relaxed version of snapToMap (or other function), it would simply block until the indexing in the background has finished. For QgsPointLocator, rather than having the whole class either sync or async, it may be good to have init() and initAsync() and also have relaxed versions of the search functions like nearestVertex or nearestEdge. |
fac5c8f
to
3de2eff
Compare
@wonder-sk Thanks for your review
Yes, indeed
Main reasons was :
Don't you think that adding a relaxed version for all 8 methods (nearestVertex, nearestArea, edgesInrect...) will add complexity, meaning it would add 3 methods per each(nearestVertex, nearestVertexRelaxed and _nearestVertex private one) ? Isn't an asynchronous boolean (default to false) a better option? Same remark apply to snapToMap |
Yeah, it is a bit tricky decision to do. My intention was mainly to avoid the boolean trap in API, to have the code easier to read: https://ariya.io/2011/08/hall-of-api-shame-boolean-trap |
interesting read, I understand your point. But I think I prefer the boolean way over having too much methods. If we stick to the boolean way, I propose to remove the snapToMapRelaxed and add a boolean to snapToMap in order to have the QgsSnappingUtils and QgsPointLocator consistent. Are you agree?
I renamed it "relaxed". |
Yeah sounds good to me! |
83c23af
to
8d42f6a
Compare
Done b06cee2 I had to fix QgsTaskManager::waitForFinished 1bde15f so it waits the task to be started before waiting to be finished |
513a657
to
dd8dd80
Compare
I create a PR #32453 for waitforfinished fix. This later should be merged before this one. |
4f10d1e
to
23c6508
Compare
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.
The code is looking really good, just few notes from me...
23c6508
to
95a100b
Compare
Thanks for the updates! Can we get rid of the rebuildIndexFinished() signal as well? it should be unused now - then I think we should be good to go :) |
Yes, done! Thanks for the time spending reviewing this PR (and the one before) |
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.
Cool - let's get it merged!
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub.
git fetch
# Create new working tree.
git worktree add .worktrees/backport release-3_10
# Navigate to the new directory.
cd .worktrees/backport
# Cherry-pick all the commits of this pull request and resolve the likely conflicts.
git cherry-pick f96e1922cae31c43cded24bb87793f26c50129d5 0bf527f54da19ad9941ee4be90e30aa6ea427f4c 7fd98e8782dccc365c716fdd79e65457e8781e3b f03da03d33c7924198493ffbfa283d6e533d044b d246d9f5930a45a2fbd30cd3727a8cc4632b36c3 d0e26fb3bca2d984625e74cc38b1ea872ddd6107 95a100bcc4db64bafe3273a86e0d58e4f28a5e2d 2cb391aeda06b387c986d7b63136a2f83e92320a 340651b2f73c226f3eced8dc705324cbe4246f0d
# Create a new branch with these backported commits.
git checkout -b backport-31648-to-release-3_10
# Push it to GitHub.
git push --set-upstream origin backport-31648-to-release-3_10
# Go back to the original working tree.
cd ../..
# Delete the working tree.
git worktree remove .worktrees/backport Then, create a pull request where the |
Description
This PR fixes the issue related to this PR #31374.
EDIT: It now also contains PR #31374 commits because it has been reverted for 3.10.0 in #32297
The snapToCurrentLayer method doesn't prepare the index and expect to be executed synchronously. So the temporary point locator must be synchronous.
It also fixes the crashes on exit.
Checklist
Fixes #11111
at the bottom of the commit messagescripts/prepare-commit.sh
script before each commit