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

Benchmark python specfile a bit #2777

Closed
praiskup opened this issue Jun 19, 2023 · 13 comments · Fixed by #2800
Closed

Benchmark python specfile a bit #2777

praiskup opened this issue Jun 19, 2023 · 13 comments · Fixed by #2800
Assignees

Comments

@praiskup
Copy link
Member

We are going to process all spec files with python-specfile now. We already count with parse errors, though parsing might be really expensivefor some packages. We should test it on texlive.spec e.g.

@praiskup
Copy link
Member Author

@xsuchy claims it is non-problem

@praiskup praiskup reopened this Jun 21, 2023
@praiskup praiskup self-assigned this Jun 21, 2023
@praiskup
Copy link
Member Author

from specfile import Specfile
import time

specfile_path = "texlive.spec"

script_start = start = time.time()

def benchmark(message):
    global start
    now = time.time()
    print(f"{message}: {now-start} seconds")
    start = now


spec = Specfile(specfile_path)
benchmark("loaded")

print(spec.expanded_name)
benchmark("name parsed")
print(spec.expanded_epoch)
benchmark("epoch parsed")
print(spec.expanded_version)
benchmark("version parsed")
print(spec.expanded_release)
benchmark("release parsed")

print(f"The script took {time.time() - script_start} seconds")

Running the script, it hangs for a few minutes here:

loaded: 15.034465312957764 seconds
Getting name

@praiskup
Copy link
Member Author

Continues:

name parsed: 1852.5356392860413 seconds
Getting epoch

@praiskup
Copy link
Member Author

Memory consumption 827M, seems acceptable for the builder, not sure about backend.

@praiskup
Copy link
Member Author

I accidentally canceled the terminal, but the epoch was parsed after another ~1750s. On i7-10850H. @nforro, isn't there a trick to do this faster than in say 2 minutes?

@nforro
Copy link
Contributor

nforro commented Jun 21, 2023

Sorry, this is crazy. Let me try to do some optimizations.

@nforro
Copy link
Contributor

nforro commented Jun 21, 2023

With packit/specfile#240, on my laptop:

loaded: 4.407037734985352 seconds
texlive
name parsed: 6.255786657333374 seconds
11
epoch parsed: 10.084052324295044 seconds
2023
version parsed: 9.657040357589722 seconds
69
release parsed: 16.89114236831665 seconds
The script took 47.29507040977478 seconds

To make it faster, you can do this (to parse tags only once):

spec = Specfile(specfile_path)
benchmark("loaded")

tags = spec.tags().content
print(tags.name.expanded_value)
benchmark("name parsed")
print(tags.epoch.expanded_value)
benchmark("epoch parsed")
print(tags.version.expanded_value)
benchmark("version parsed")
print(tags.release.expanded_value)
benchmark("release parsed")

print(f"The script took {time.time() - script_start} seconds")

Result:

loaded: 5.885213136672974 seconds
texlive
name parsed: 9.854274272918701 seconds
11
epoch parsed: 0.0469050407409668 seconds
2023
version parsed: 0.04676461219787598 seconds
69.fc37
release parsed: 0.05761575698852539 seconds
The script took 15.89078426361084 seconds

@nforro
Copy link
Contributor

nforro commented Jun 21, 2023

Oh, and to get release without the dist tag, you can do:

print(spec.expand(tags.release.value, extra_macros=[("dist", "")]))

But it will slow things down a bit again:

loaded: 4.443751811981201 seconds
texlive
name parsed: 8.05765676498413 seconds
11
epoch parsed: 0.04661202430725098 seconds
2023
version parsed: 0.04650592803955078 seconds
69
release parsed: 7.663807153701782 seconds
The script took 20.258345365524292 seconds

@praiskup
Copy link
Member Author

Nice, thank you for the fix, @nforro! This is likely one of the worst scenarios, and if we can parse such a spec file in less than a minute, it is more than good.

@praiskup
Copy link
Member Author

Once in stable, we should Require: python3-specfile >= 0.19.0.

@praiskup
Copy link
Member Author

@praiskup praiskup assigned FrostyX and unassigned praiskup Jun 28, 2023
@praiskup
Copy link
Member Author

Jakub promised to specify the specific version in our specfiles once it is in stable (changed assignee).

@praiskup
Copy link
Member Author

#2800 fixes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants