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

Predoc: Fix quadratic complexities in nest and offset #212

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

Conversation

dasJ
Copy link
Member

@dasJ dasJ commented Jul 1, 2024

I honestly don't understand why this makes it faster, but for me the test suite runs ~2s faster now. This is an AI-generated contribution. The GPT explanation is:

By abstracting the transformation logic into a single function transform, we can pass different transformations for nesting and offsetting. This way, we avoid repeated traversals and ensure each element is processed exactly once.

This change ensures linear complexity for the nest and offset functions. We leverage the map function to traverse and transform the Doc structure only once, applying the necessary changes to each element.

Copy link

github-actions bot commented Jul 1, 2024

Nixpkgs diff

I honestly don't understand why this makes it faster, but for me the
test suite runs ~2s faster now. This is an AI-generated contribution.
The GPT explanation is:

By abstracting the transformation logic into a single function `transform`, we can pass different transformations for nesting and offsetting. This way, we avoid repeated traversals and ensure each element is processed exactly once.

This change ensures linear complexity for the `nest` and `offset` functions. We leverage the `map` function to traverse and transform the `Doc` structure only once, applying the necessary changes to each element.
@dasJ dasJ force-pushed the fix/quadratic-complexities branch from ee4d421 to 508917f Compare July 1, 2024 12:32
@piegamesde
Copy link
Member

Someone who actually knows Haskell should vet this, but my gut feeling is that the complexity is still quadratic, and that the performance improvement is of other nature (or just measurement noise).

@dasJ
Copy link
Member Author

dasJ commented Jul 1, 2024

Now that I look at it, isn't nest x the same as offset 1 x?

@piegamesde
Copy link
Member

They're doing similar things but on different fields of Text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

None yet

2 participants