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

Split APIHelper out into its own file #137

Merged
merged 3 commits into from
Nov 29, 2023
Merged

Conversation

n-peugnet
Copy link
Contributor

@n-peugnet n-peugnet commented Nov 20, 2023

This allow to only import it when needed, speeding up the CLI for easy tasks, especially the auto-completion provided by click (that I intend to add to the Debian package). This is most noticable when site packages are enabled (as with the command python -m virtualenv --system-site-packages) or on global installations, like with the official Debian package.

Before

$ time synadm > /dev/null
real	0m0,610s
user	0m0,537s
sys	0m0,072s

After

$ time synadm > /dev/null
real	0m0,086s
user	0m0,077s
sys	0m0,009s

References

This allow to only import it when needed, speeding up the CLI for easy tasks,
especially the auto-completion provided by click [1]. This is most
noticable when site packages are enabled (as with the command "python -m
virtualenv --system-site-packages") or on global installations, like with
the official Debian package.

Before

	$time synadm > /dev/null
	real	0m0,610s
	user	0m0,537s
	sys	0m0,072s

After

	$time synadm > /dev/null
	real	0m0,086s
	user	0m0,077s
	sys	0m0,009s

[1]: https://click.palletsprojects.com/en/latest/shell-completion/
@JacksonChen666
Copy link
Collaborator

Some actual benchmarking:

> hyperfine --warmup 10 "/opt/homebrew/bin/synadm" synadm
Benchmark 1: /opt/homebrew/bin/synadm
  Time (mean ± σ):     114.0 ms ±   1.9 ms    [User: 94.8 ms, System: 17.1 ms]
  Range (min … max):   110.3 ms … 120.3 ms    25 runs

Benchmark 2: synadm
  Time (mean ± σ):      45.2 ms ±   0.7 ms    [User: 37.3 ms, System: 6.7 ms]
  Range (min … max):    42.6 ms …  46.5 ms    60 runs

Summary
  synadm ran
    2.52 ± 0.06 times faster than /opt/homebrew/bin/synadm

/opt/homebrew/bin/synadm is synadm 0.43.1, synadm is this PR

@JacksonChen666
Copy link
Collaborator

JacksonChen666 commented Nov 20, 2023

Before

$ time synadm > /dev/null
real	0m0,610s
user	0m0,537s
sys	0m0,072s

This really looks like filesystem caching in action, so this benchmark likely isn't good.

@n-peugnet
Copy link
Contributor Author

n-peugnet commented Nov 20, 2023

Some actual benchmarking

Thank you, I wasn't motivated enough to do it!

This really looks like filesystem caching in action, so this benchmark likely isn't good.

Not really, I didn't take the first run, subsequent runs are all about the same time.

Details

$ for i in $(seq 10); do time synadm > /dev/null; done

real	0m0,619s
user	0m0,539s
sys	0m0,080s

real	0m0,600s
user	0m0,508s
sys	0m0,092s

real	0m0,612s
user	0m0,544s
sys	0m0,068s

real	0m0,597s
user	0m0,537s
sys	0m0,060s

real	0m0,643s
user	0m0,568s
sys	0m0,076s

real	0m0,606s
user	0m0,523s
sys	0m0,084s

real	0m0,601s
user	0m0,532s
sys	0m0,068s

real	0m0,609s
user	0m0,529s
sys	0m0,080s

real	0m0,601s
user	0m0,569s
sys	0m0,032s

real	0m0,595s
user	0m0,495s
sys	0m0,100s

Also note that it really depends on the quantity of python libraries installed on the system. For instance in a bare-bones virtualenv the difference it is almost not noticeable.

@JacksonChen666
Copy link
Collaborator

JacksonChen666 commented Nov 20, 2023

Also note that it really depends on the quantity of python libraries installed on the system. For instance in a bare-bones virtualenv it is almost not noticeable.

Hmm, I'll try barebones venv in both cases later.

@n-peugnet
Copy link
Contributor Author

Also note that it really depends on the quantity of python libraries installed on the system. For instance in a bare-bones virtualenv it is almost not noticeable.

Hmm, I'll try barebones venv in both cases later.

Sorry I meant the difference is almost not noticeable. Meaning it is almost the same time for both my changes and master.

@n-peugnet
Copy link
Contributor Author

Some more numbers to explain the differences:

$ # master in venv made with `python -m virtualenv --system-site-packages`
$ strace synadm 2>&1 | wc -l
13251
$ # this branche in venv made with `python -m virtualenv --system-site-packages`
$ strace synadm 2>&1 | wc -l
1668
$ # master in normal venv
$ strace synadm 2>&1 | wc -l
4448
$ # this branch in normal venv
$ strace synadm 2>&1 | wc -l
1537

Copy link
Owner

@JOJ0 JOJ0 left a comment

Choose a reason for hiding this comment

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

Hi to both of you,
awesome idea. Splitting out into a separate file is a good idea even if it was not for performance. I didn't realize that there is a Debian package and you are the maintainer @n-peugnet, that is great news as well! Thanks so much for taking care of that. Tab completion for synadm also sounds like a very handy feature for the package. We certainly should work towards making that a pleasent user experience.

One change request: Please let's name that file _helper.py.

@n-peugnet
Copy link
Contributor Author

I didn't realize that there is a Debian package and you are the maintainer @n-peugnet

I am not the official maintainer but I intend to send him a patch to add the completion script in the package.

Tab completion for synadm also sounds like a very handy feature for the package. We certainly should work towards making that a pleasent user experience.

This is exactly when testing this completion script (generated by click) that loads the python project each time that I noticed the startup was quite slow.

One change request: Please let's name that file _helper.py.

I can do that in a few days. Not that much time right now.

@JacksonChen666
Copy link
Collaborator

One change request: Please let's name that file _helper.py.

I can do that in a few days. Not that much time right now.

would it be fine if i did it?

@n-peugnet
Copy link
Contributor Author

would it be fine if i did it?

Yes of course!

@JacksonChen666
Copy link
Collaborator

would it be fine if i did it?

Yes of course!

hmmm, do you have maintainer edits enabled? doesn't seem like it to me.

if you do have time, you can do it yourself instead.

@n-peugnet
Copy link
Contributor Author

hmmm, do you have maintainer edits enabled? doesn't seem like it to me.

Sorry, I thought I did.

if you do have time, you can do it yourself instead.

Just did it now.

@n-peugnet n-peugnet requested a review from JOJ0 November 24, 2023 15:24
@JOJ0
Copy link
Owner

JOJ0 commented Nov 29, 2023

Hi, sorry for the delay @n-peugnet . I just wanted to quickly add some refinements to the docstrings of the modules. Are you sure you have maintainer edits enabled?

Copy link
Owner

@JOJ0 JOJ0 left a comment

Choose a reason for hiding this comment

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

Nevermind, added module-level docstring refinements as code suggestions.

synadm/cli/__init__.py Outdated Show resolved Hide resolved
synadm/cli/_helper.py Outdated Show resolved Hide resolved
@n-peugnet n-peugnet requested a review from JOJ0 November 29, 2023 14:27
@JOJ0 JOJ0 merged commit a749d76 into JOJ0:master Nov 29, 2023
1 check passed
@n-peugnet n-peugnet deleted the split-api-helper branch November 29, 2023 16:14
JOJ0 added a commit that referenced this pull request Jul 26, 2024
After moving APIHelper to its own file _helper.py in #137, the class was not
found by Sphinx autodoc anymore, thus missing in the docs and we didn't catch
the warning at build time.
JOJ0 added a commit that referenced this pull request Jul 26, 2024
After moving APIHelper to its own file _helper.py in #137, the class was not
found by Sphinx autodoc anymore, thus missing in the docs and we didn't catch
the warning at build time.
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