Skip to content

Commit 2720c4c

Browse files
perf: Faster session startup by defering anon dataset fetch (#1982)
1 parent 204f083 commit 2720c4c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bigframes/session/anonymous_dataset.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import datetime
16+
import threading
1617
from typing import List, Optional, Sequence
1718
import uuid
1819

@@ -40,19 +41,30 @@ def __init__(
4041
):
4142
self.bqclient = bqclient
4243
self._location = location
43-
self.dataset = bf_io_bigquery.create_bq_dataset_reference(
44-
self.bqclient,
45-
location=self._location,
46-
)
4744

4845
self.session_id = session_id
4946
self._table_ids: List[bigquery.TableReference] = []
5047
self._kms_key = kms_key
5148

49+
self._dataset_lock = threading.Lock()
50+
self._datset_ref: Optional[bigquery.DatasetReference] = None
51+
5252
@property
5353
def location(self):
5454
return self._location
5555

56+
@property
57+
def dataset(self) -> bigquery.DatasetReference:
58+
if self._datset_ref is not None:
59+
return self._datset_ref
60+
with self._dataset_lock:
61+
if self._datset_ref is None:
62+
self._datset_ref = bf_io_bigquery.create_bq_dataset_reference(
63+
self.bqclient,
64+
location=self._location,
65+
)
66+
return self._datset_ref
67+
5668
def _default_expiration(self):
5769
"""When should the table expire automatically?"""
5870
return (

0 commit comments

Comments
 (0)