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

Low Hanging Fruit (aka obvious stuff) #15

Open
Robadob opened this issue Jan 31, 2024 · 3 comments
Open

Low Hanging Fruit (aka obvious stuff) #15

Robadob opened this issue Jan 31, 2024 · 3 comments

Comments

@Robadob
Copy link
Member

Robadob commented Jan 31, 2024

When you begin writing code, and the plan changes half way through it's easy for bottlenecks that weren't previously a problem to appear. These can be recognised and easily addressed, they mostly revolve around redundant repetition.

  • Repeating the same operation to calculate a value every iteration of a loop (move the operation outside the loop so that it's performed once)
  • Regularly calling a function that performs an expensive operation to return a predictable result (cache results, LRU cache decorator).
  • Reading the same file from disk multiple times (read it once and cache it in memory).
  • ??
@Robadob
Copy link
Member Author

Robadob commented Feb 8, 2024

Worth using the applicable items from the COM4521 lecture 2b.

Call it first steps or similar.

@JostMigenda
Copy link
Collaborator

  • Regularly calling a function that performs an expensive operation to return a predictable result (cache results, LRU cache decorator).

Yes—memoization was also on the list of things I considered adding (but didn’t get to for our first run). With [functools.cache](https://docs.python.org/3/library/functools.html#functools.cache), that’s just a 1 line change, so hopefully shouldn’t take up too much time? Factorial or Fibonacci could both make for a good demo.

@Robadob
Copy link
Member Author

Robadob commented Mar 7, 2025

Similar to the short snippet about filter your data before processing not after, it feels too short/brief for people to take it in. Lack of a decent example stopped me adding this, functools cache could work though.

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

No branches or pull requests

2 participants