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
- Google Chrome v. 91.0.4472.101
- 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): base = crystal_price + add 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) return total_cost, actual_payout, stones
Thank you in advance!