-
Notifications
You must be signed in to change notification settings - Fork 173
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
Speed improvements on Record init #658
Comments
Latest benchmark after adding a cache of endpoints on
|
@srfwx can you provide a PR for it so we can review it? It sounds beneficial but hard to say without seeing the exact code. |
Hi, |
Further improvement achieved by only computing the Record.endpoint on demand and not during init. (0f9e41b)
|
I've noticed that nested Record are instantiated from scratch each time, although when dealing with a RecordSet you'll likely be encountering the same sub Record many times. Hence temporarily caching and re-using instead of processing again lead to even better performance. My benchmark is now showing a ~90% improvement
💡 This also gives the benefit that if you call |
Nested dictionaries representing a Choice value are instantiated as nested |
pynetbox version
v7.4.1
NetBox version
v4.1.7
Feature type
Change to existing functionality
Proposed functionality
Hi,
We've built a caching layer to Pynetbox where responses are stored as json inside a Redis cache, then Record objects are reconstructed from there on cache hit.
However I've noticed that the
_init_
of aRecord
object can still take a substantial amount of time due to the various processing stepsAs a first step I have:
_endpoint_from_url
method so that it doesn't needurlsplit
leading to a 50% speed improvement of that method_parse_values
method to limit the number of instance type checking and number of key/value that need further processingAll in all, according to a few benchmarks I made, the whole Record init shows more than 50% speed improvement. Below is an example when loading 14407 records.
Benchmark using cProfile with Pynetbox v7.4.1
Benchmark using cProfile with our fork
Would you be interested in having any/all of these things merged into upstream?
Use case
General speed improvement of the library
External dependencies
None
The text was updated successfully, but these errors were encountered: