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

[KED-2365] Simplify layout algorithm, improve layout quality and performance #398

Merged
merged 5 commits into from
Apr 1, 2021

Conversation

bru5
Copy link
Contributor

@bru5 bru5 commented Mar 16, 2021

Description

Simplify layout algorithm, improve layout quality and performance.

Development notes

Performance and algorithmic improvements:

  • simplified and reduced overall implementation
  • reduced average complexity / run time
  • reduced memory usage and garbage collection

Example performance change for 868 nodes + 1555 edges test case

  • 56% time reduction (2.27x speedup)
  • 91% less object allocation

Output changes and quality improvements:

  • consistently compact layouts
  • improved node alignment, regularity, symmetry, linearity
  • increased spacing around nodes with high number of edges
  • improved layout spacing and routing when node labels enabled
  • added more specific constraint tests

QA notes

Check various pipelines, selections and compare results with main branch.

Load time should be significantly reduced and larger pipelines should show some visual improvement described above.

Results may look somewhat different than previous renderings but in general should be as good or better than before.

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added new entries to the RELEASE.md file
  • Added tests to cover my changes

Legal notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

  • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.

  • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorised to submit this contribution on behalf of the original creator(s) or their licensees.

  • I certify that the use of this contribution as authorised by the Apache 2.0 license does not violate the intellectual property rights of anyone else.

@bru5 bru5 self-assigned this Mar 16, 2021
@@ -16,7 +16,7 @@ import {
* @param {array} params.nodes The input nodes
* @param {array} params.edges The input edges
* @param {object=} params.layers The node layers if specified
* @param {number} params.basisX The basis relating diagram width in X
* @param {number} params.spreadX The amount to adapt spacing in X
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what is the main motivation behind adapting spacing instead of the relation to the width of the diagram, and how does it improve the layout engine? It would be worth mentioning which goal this change relates to in the PR decription.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I've updated the comment here to make it a bit clearer what that parameter does, though it's not really expected that this value will change from the included default constant which is pretty implementation relative and was found by trial and error.

If you're really curious though it's worth following the parameter through the code and playing with the value while watching in the browser.

}

// Update separation constraints but ensure spacing is exact
updateSeparationConstraints(separationConstraints, rows, spaceX, true);
// Constraints to maintain a minimum horizontal node spacing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is very interesting! Similar to my comment above, it would be great to document the reasoning / motivation behind this change in the PR description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this part was just a refactoring and simplification so I've not much to add on that.

Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for introducing these improvements @bru5 , I haven't extensively tested the new layout yet, I'm sure it's good stuff!

Just some initial comments:

  • I notice in the PR decription on the list of improvements, but seems to be missing the 'how' - I notice the various changes that was introduced in this PR, such as change in constraints, etc, and it would be great if you could include the explanation of the relating changes for each improvement so whoever reviewing this understand and relate the changes with the motivations behind. Currently it's a bit of a guessing game in understanding and relating the how to the list of improvements.
  • There are a lot of calculations for the constraints - these needs unit tests.

I will have a more thorough read and further poke around and let you know if I see anything!

@limdauto
Copy link
Collaborator

+1 to @studioswong's suggestion. I would love to know how these improve the current engine for future reference.

Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tested out the graph, the new layout and improvements looks good! I notice that these new constraints and improvement only apply to the new graph - I persume these improvements does not apply to the old Dagre graph layout?

Following my previous comment, the constraints itself now contains quite a bit of calculations - tests would need to set up for these calculations within the constraints. I notice that there is currently no test file set up for constraints.js - perhaps it's time we set one up to ensure the constraints are correctly tested?

Thank you!

Copy link
Contributor

@richardwestenra richardwestenra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

src/utils/graph/layout.js Outdated Show resolved Hide resolved
@bru5
Copy link
Contributor Author

bru5 commented Apr 1, 2021

Thanks for the comments all, I've now added more specific tests for each constraint.

I realise there is still some way to go in explaining the algorithm at a higher level than the implementation. I'll work on a higher level supporting document for that, since this is not particularly straightforward and is very abstract.

Often I do find that code comments are not the best format for discussing things at a high level, for now they are describing the specific implementation and the API but I can definitely add cross references once complete.

@bru5 bru5 merged commit c753ef7 into main Apr 1, 2021
@bru5 bru5 deleted the feature/improve-graph branch April 1, 2021 17:35
limdauto pushed a commit that referenced this pull request Apr 9, 2021
…ormance (#398)

* [KED-2365] Simplify graph algorithm, improve graph layout quality and performance

* [KED-2528] Refactor and split graph solve functions to further simplify

* [KED-2528] Resolve crossing constraints symmetrically

* [KED-2528] Add more specific tests for layout constraints

* [KED-2528] Improve docs on graph layout functions
@studioswong studioswong mentioned this pull request Apr 16, 2021
1 task
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.

4 participants