Replies: 1 comment 25 replies
-
Could you fetch |
Beta Was this translation helpful? Give feedback.
25 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Ok, so this is some major metaproogramming question. Rationale:
In our project we have a plethora of type/class instances which have the same signature and are frozen after creation, hence the instances can be shared. But an upfront singleton type approach is not really practical for our purposes. For that there exists already a Python package called mementos which implements the Memento-pattern:
https://pypi.org/project/mementos/
It is relatively simple: It creates a dict key out of the class and it's calling signature, saves the instance in a dict, and overrides the call function of a class that inherits the metaclass menentos. If the class is being created somewhere else with the same signature, the same instance is returned again instead of creating a new one.
As this inital creation and lookup is very performance critical in our project we want to try if we can gain anything by essentially re-implenting this in rust. I just tried to replace the key generation functioon and this actually made it slower, soo now I am looking into moving the whole dict into a rust hashmap and just handing in the signature and retuning a new or cached instance, so essentially I want to oxidize this call function from the mementos package, alternatively one could also replace the whole outer metaclass factory but that might not be worth it:
My problem are the calls to 'type'. I cannot really find the equivalent for that in pyoo3, oor I misunderstand the docs.
Or can I just create the instance based on cls which is handed to me?
If I write cls.call(*args, **kwargs) in python that will lead to infinite recursion.
Any tips are appreciated.
Beta Was this translation helpful? Give feedback.
All reactions