Skip to content

Use a Set to track visited exprs. #198

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

Merged

Conversation

dylansturg
Copy link
Contributor

As part of contextual breaks, some expressions are visited ahead of their visit method by traversing nested expressions and inserting contextual breaks. Already visited expressions were tracked using an array. Since this was purely for looking up which expressions were already visited, a set is much faster for lookup.

This has a significant performance impact for files that contain many expressions, but minimal impact for files with few exprs (essentially large files vs small files). I tested formatting all of swift-protobuf and a single large (10k LOC) file. The times are an average from running 4 times.

  • Large file: original 12.9 seconds, modified 2.4 seconds
  • swift-protobuf: original 24.2 seconds, modified 21.4 seconds

@allevato allevato merged commit 34ccba1 into swiftlang:master Jun 8, 2020
@dylansturg dylansturg deleted the sets_are_faster_for_searching branch June 8, 2020 18:41
aaditya-chandrasekhar pushed a commit to val-verde/swift-format that referenced this pull request May 20, 2021
Verifies that generated `all.css` contains the `:root` string on CI. It doesn't do any actual CSS parsing to verify its full validity, only does a simple `grep` check, but I hope this will be enough to prevent issues like swiftlang#198 in the future.

* Test that `all.css` contains a valid CSS selector

* Update `CHANGELOG.md`

* Install graphviz to avoid warnings on macOS

* Add EndToEndTests subclassing XCTest

* Apply suggestions from code review

Co-authored-by: Mattt <[email protected]>

* Remove stray comment leftover from review

* Set macOS 10.13 as minimum platform target

* Refactor EndToEndTests

Create helper methods on Process and Bundle

* Test whether generated HTML output contains subdirectories

* Add test for CommonMark output

* Add tests for coverage subcommand

* Add tests for diagram subcommand

* Update Changelog entry for swiftlang#199

* Work around unavailability of hasDirectoryPath

* Update Changelog.md

Co-authored-by: Max Desiatov <[email protected]>

* Update Changelog entry for swiftlang#199

Co-authored-by: Mattt <[email protected]>
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