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

Revise entry sorting: refactor for readability, remove duplicates, sort rest alphabetically #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LinqLover
Copy link
Contributor

Duplicates can occur for variables that are also selectors in untyped models, or also due to custom hooks.

…rt rest alphabetically

Duplicates can occur for variables that are also selectors in untyped models, or also due to custom hooks.
@LinqLover
Copy link
Contributor Author

Please discuss #39 (comment) before approving this. :)

Copy link
Owner

@LeonMatthes LeonMatthes left a comment

Choose a reason for hiding this comment

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

Overall, nice refactoring, no objections to removing duplicates in principle. It shouldn't hurt performance though if possible.
If it's not too much trouble, could you benchmark this by creating a fake ECModel instance with random entries and running the old and new sortEntries functions?

If performance does indeed degrade, it may be enough and faster to only remove duplicates that are displayed directly after one another.
e.g. filter out:

  • aCue followed by
  • aCue

As that should be doable in O(n) with low constant overhead and covers the most obvious case as described in #39
May even be doable in the rendering code, which should be really fast 🤔

entries sort:
[:entry | entry matchNarrowString: narrowString] descending
, [:aEntry :bEntry | aEntry <= bEntry ifTrue: [-1] ifFalse: [0]]
Copy link
Owner

Choose a reason for hiding this comment

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

Where does the , operator on BlockClosure come from???
Is that new? It doesn't work on my system.

Or am I reading the syntax incorrectly?

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, okay, descending returns a PropertySortFunction that can be comma-chained...
That's wild 😅, but okay.

| seen |
entries sort:
[:entry | entry matchNarrowString: narrowString] descending
Copy link
Owner

Choose a reason for hiding this comment

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

Huh, cool, no idea #descending worked on BlockClosure 👍


"remove any duplicates"
seen := Set new.
Copy link
Owner

Choose a reason for hiding this comment

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

I don't mind removing duplicates, as discussed in #39 , duplicates are just a side-effect of adding all selectors in the untyped model.
There's no real point in displaying them.

How is performance though? First sorting, then converting into a Set sounds a bit expensive 🤔
Especially in the untyped model that contains all selectors.

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.

2 participants