# App Speed Improvements

Hello! I’m so excited to participate in this community and get some help with what should be ( ) a simple fix!

I’ve just deployed an application here using Heroku. Performance was excellent when I was just running in the terminal, but as soon as I started to convert into a web app, it tanked. The app will usually load well on the first try, then takes a very, very long time if I try to change any variables and get a new result. I’m almost certain someone with more CS/algorithms/data structures knowledge than I have will be able to crack the code on this one, but it could be something else, so I came here first!

Some relevant info:

• Python v. 3.7.4
• Streamlit v. 0.83.0
• PipEnv for environment
• Windows 10

Below are the two functions I believe could be slowing everything down.
A few notes:
costs is a list of floats
The app inputs correspond to add, multiply, and payout_goal, in that order

``````def charge(crystal_price, add, multiply):
cost = base * multiply
decimals = str(round(cost, 2))[2:]
if decimals == '.82':
new_cost = cost + .06
elif decimals == '.32':
new_cost = cost + .56
else:
new_cost = cost
while new_cost not in charges:
new_cost += 1
return round(new_cost, 2)

def wire_wraps(payout_goal, costs):
total_cost = 0
actual_payout = 0
stones = []
while actual_payout < payout_goal:
stone = random.choice(costs)
stones.append(stone)
total_cost += stone / 2
actual_payout += (charge(stone, add, multiply) / 2)
``````

First, It is not completely clear what `charges` is in the line `while new_cost not in charges:`.
2. Your second function. `wire_wraps()` not only has a while loops. It also calls the function `charge()` which also has it’s own while loops. This is is probably the biggest resource overhead in your code.