Skip to content

Conversation

@MiloLug
Copy link

@MiloLug MiloLug commented Apr 23, 2023

We need to process fq twice, but each subsequent item depends on previous one. That's why you previously were using two loops.

But it can be optimized to use only one loop:

For example, given jz = 10
At first, we process items # (in pairs):

  • (10, 9)
  • (9, 8) Now we can run simple loop that will process those pairs independently:
  • (10, 9), (8, 7)
  • (9, 8), (7, 6)
  • (8, 7), (6, 5)
  • so on...

This way, we can process each pair twice with only one loop

We need to process `fq` twice, but each subsequent item depends on previous one. That's why you previously were using two loops.

But it can be optimized to use only one loop:

For example, given `jz = 10`
At first, we process items # (in pairs):
  - (10, 9)
  - (9, 8) Now we can run simple loop that will process those pairs independently:
  - (10, 9), (8, 7)
  - (9, 8), (7, 6)
  - (8, 7), (6, 5)
  - so on...

This way, we can process each pair twice with only one loop
@github-actions
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
        rp2:    +0 +0.000% PICO

@codecov-commenter
Copy link

Codecov Report

Merging #11317 (cf5709d) into master (9e6885a) will not change coverage.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##           master   #11317   +/-   ##
=======================================
  Coverage   98.50%   98.50%           
=======================================
  Files         155      155           
  Lines       20549    20549           
=======================================
  Hits        20241    20241           
  Misses        308      308           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label May 8, 2023
@dpgeorge
Copy link
Member

dpgeorge commented May 8, 2023

Thanks for the contribution.

I'd be reluctant to modify this code, because it's taken from the musl project and not developed here.

Also, it's not clear that this is an optimisation because there is still 2 loops in the second "else". Furthermore, we usually optimise for small code size, rather than performance. As such, it would be important to show that this does actually make the code faster, and that that improvement in speed is worth the cost of increased code size.

@dpgeorge dpgeorge closed this Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants