From 0c47a53b5ece01d5740eea7203400b0f90ce2f15 Mon Sep 17 00:00:00 2001 From: adrianeboyd Date: Sun, 16 Feb 2020 17:19:41 +0100 Subject: [PATCH] Use int only in key2row for better performance (#4990) Cast all keys and rows to `int` in `vectors.key2row` for more efficient access and serialization. --- spacy/vectors.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spacy/vectors.pyx b/spacy/vectors.pyx index 6b26bf123..c6526b89d 100644 --- a/spacy/vectors.pyx +++ b/spacy/vectors.pyx @@ -283,7 +283,11 @@ cdef class Vectors: DOCS: https://spacy.io/api/vectors#add """ - key = get_string_id(key) + # use int for all keys and rows in key2row for more efficient access + # and serialization + key = int(get_string_id(key)) + if row is not None: + row = int(row) if row is None and key in self.key2row: row = self.key2row[key] elif row is None: