Skip to content
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

[WIP] Adding config setting to disable singleton cache #3956

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/user_guide/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ FiftyOne supports the configuration options described below:
| | | | operations such reading/writing large datasets or activating FiftyOne |
| | | | Brain methods on datasets. |
+-------------------------------+-------------------------------------+-------------------------------+----------------------------------------------------------------------------------------+
| `singleton_cache` | `FIFTYONE_SINGLETON_CACHE` | `True` | Whether to treat :class:`Dataset <fiftyone.core.dataset.Dataset>`, |
| | | | :class:`Sample <fiftyone.core.sample.Sample>`, and |
| | | | :class:`Frame <fiftyone.core.frame.Frame>` instances as singletons. |
+-------------------------------+-------------------------------------+-------------------------------+----------------------------------------------------------------------------------------+
| `timezone` | `FIFTYONE_TIMEZONE` | `None` | An optional timezone string. If provided, all datetimes read from FiftyOne datasets |
| | | | will be expressed in this timezone. See :ref:`this section <configuring-timezone>` for |
| | | | more information. |
Expand Down Expand Up @@ -182,6 +186,7 @@ and the CLI:
"plugins_dir": null,
"requirement_error_level": 0,
"show_progress_bars": true,
"singleton_cache": true,
"timezone": null
}

Expand Down Expand Up @@ -231,6 +236,7 @@ and the CLI:
"plugins_dir": null,
"requirement_error_level": 0,
"show_progress_bars": true,
"singleton_cache": true,
"timezone": null
}

Expand Down
6 changes: 6 additions & 0 deletions fiftyone/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ def __init__(self, d=None):
env_var="FIFTYONE_MAX_PROCESS_POOL_WORKERS",
default=None,
)
self.singleton_cache = self.parse_bool(
d,
"singleton_cache",
env_var="FIFTYONE_SINGLETON_CACHE",
default=True,
)

self._init()

Expand Down
15 changes: 10 additions & 5 deletions fiftyone/core/singletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from collections import defaultdict
import weakref

import fiftyone as fo


class DatasetSingleton(type):
"""Singleton metaclass for :class:`fiftyone.core.dataset.Dataset`.
Expand Down Expand Up @@ -44,7 +46,8 @@ def __call__(cls, name=None, _create=True, *args, **kwargs):
name=name, _create=_create, *args, **kwargs
)

cls._instances[name] = instance
if fo.config.singleton_cache:
cls._instances[name] = instance

return instance

Expand Down Expand Up @@ -107,7 +110,8 @@ def __new__(metacls, *args, **kwargs):
return cls

def _register_instance(cls, obj):
cls._instances[obj._doc.collection_name][obj.id] = obj
if fo.config.singleton_cache:
cls._instances[obj._doc.collection_name][obj.id] = obj

def _get_instance(cls, doc):
try:
Expand Down Expand Up @@ -252,9 +256,10 @@ def __new__(metacls, *args, **kwargs):
return cls

def _register_instance(cls, obj):
cls._instances[obj._doc.collection_name][obj.sample_id][
obj.frame_number
] = obj
if fo.config.singleton_cache:
cls._instances[obj._doc.collection_name][obj.sample_id][
obj.frame_number
] = obj

def _get_instance(cls, doc):
try:
Expand Down
Loading