idaholab / MontePy

MontePy is the most user friendly Python library (API) to read, edit, and write MCNP input files.
https://www.montepy.org/
MIT License
30 stars 6 forks source link

Implement singleton pattern for Immutable objects #550

Open MicahGale opened 1 week ago

MicahGale commented 1 week ago

There are a few immutable objects that are frequently used, namely: Element. There's no reason that these instances couldn't be shared so a "singleton-like" pattern might help save memory.

I confirmed this was note the case:

In [1]: import montepy

In [2]: el1= montepy.data_inputs.element.Element(92)

In [3]: el2= montepy.data_inputs.element.Element(92)

In [4]: hex(id(el1))
Out[4]: '0x7fa5c7d14410'

In [5]: hex(id(el2))
Out[5]: '0x7fa5f8b4f770'