-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as not planned
Closed as not planned
Copy link
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-tkintertype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Just run the code below:
import timeit
print(timeit.timeit("tk.winfo_rgb('red')", "import tkinter; tk = tkinter.Tk()"))
# 11.070131499999661
# Control group:
print(timeit.timeit("tk.winfo_id()", "import tkinter; tk = tkinter.Tk()"))
# 0.4995561000005182
You can see that this operation is too slow. The method winfo_rgb
is also specific to the return value for a specific input, so I tried using decorator functools.lru_cache
to speed up multiple calls to the method.
Here's what happens when using decorators:
import timeit
print(timeit.timeit("tk.winfo_rgb('red')", "import tkinter; tk = tkinter.Tk()"))
# 0.036084200000004785
If a user doesn't test the speed of the method, he/she may never know that the method is called so slowly (This can cause him/her to call the method with the same parameter multiple times), so I think it's necessary to speed up multiple calls to the method by caching.
My test environment:
- Python:
3.13.0
- OS: Windows 24H2
If there are any problems with my idea, please feel free to point it out, thank you!
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-tkintertype-featureA feature request or enhancementA feature request or enhancement