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

Fix performance impact of exception handling in _is_annotation_tid() #925

Merged
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
12 changes: 4 additions & 8 deletions forte/data/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ def fetch_entry_type_data(
else:
attr_fields: Dict = self._get_entry_attributes_by_class(type_name)
for attr_name, attr_info in attr_fields.items():

attr_class = get_origin(attr_info.type)
# Since we store the class specified by get_origin,
# if the output it None, we store the class for it,
Expand Down Expand Up @@ -1047,7 +1046,6 @@ def _add_entry_raw(
self._is_subclass(type_name, cls)
for cls in (list(SinglePackEntries) + list(MultiPackEntries))
):

try:
self.__elements[type_name].append(entry)
except KeyError:
Expand Down Expand Up @@ -1081,10 +1079,7 @@ def _is_annotation_tid(self, tid: int) -> bool:
elif tid in self.__tid_idx_dict:
return False
else:
raise KeyError(
f"Entry with tid {tid} not found."
f" Data store content is only {str(self.__dict__)}"
)
raise KeyError(f"Entry with tid {tid} not found.")

def _create_new_entry(
self, type_name: str, tid: Optional[int] = None
Expand Down Expand Up @@ -1246,7 +1241,6 @@ def add_entry_raw(
allow_duplicate: bool = True,
attribute_data: Optional[List] = None,
) -> int:

r"""
This function provides a general implementation to add all
types of entries to the data store. It can add namely
Expand Down Expand Up @@ -1870,7 +1864,9 @@ def co_iterator_annotation_like(
self.get_datastore_attr_idx(tn, constants.BEGIN_ATTR_NAME),
self.get_datastore_attr_idx(tn, constants.END_ATTR_NAME),
)
except IndexError as e: # all_entries_range[tn][0] will be caught here.
except (
IndexError
) as e: # all_entries_range[tn][0] will be caught here.
raise ValueError(
f"Entry list of type name, {tn} which is"
" one list item of input argument `type_names`,"
Expand Down