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

tsort: drastically reduce memory copies #5969

Merged
merged 1 commit into from
Feb 11, 2024

Conversation

tertsdiepraam
Copy link
Member

@tertsdiepraam tertsdiepraam commented Feb 11, 2024

To reduce the copying happening in tsort, we can load the entire input in memory and only refer to slices within that input instead of allocating a String for each occurrence of a node.

cc @anastygnome

On my input generated with:

import random

random.seed(0)

N = 10000
for i in range(100*N):
    a = random.randint(0,N)
    b = random.randint(0,N)
    if a != b:
        print(f"{min(a, b)} {max(a, b)}")

The time measured with hyperfine drops from ~2.3 seconds to ~1.6 seconds.

@anastygnome
Copy link
Contributor

Nice, please set a fixed seed for reproducibility tho :)

@tertsdiepraam
Copy link
Member Author

Fair :)

@sylvestre sylvestre merged commit e3c10bc into uutils:main Feb 11, 2024
53 of 59 checks passed
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.

3 participants