在 MongoDB 上使用 UUID 而不是其字符串表示作为 _id 的性能提升?

Performance gains to using UUID instead of its string representation as _id on MongoDB?

在 REST 应用程序中,我需要将 UUID 字符串表示形式(在 json 中接收)转换为 UUID Object 以将其存储在 MongoDB 的 _id 场地。我这样做是因为我听说使用 UUIDString.

相比,在 lookup/insertion 时间内性能有所提高

在 MongoDB 上将 UUID 用作 _id 而不是其字符串表示形式时,真的会提高性能吗? (即使是很小的性能提升也会对我产生很大的影响)

PS:我看到 this postObjectID 的性能更好(不完全相同,不确定是否适用于 UUID),但唯一原因似乎是 ObjectIDString.

的潜在较小尺寸

我正在使用 PyMongo,它将 UUID 编码为 BSON::Binary

MongoDB doc可以看出:

For a more efficient storage of the UUID values in the collection and in the _id index, store the UUID as a value of the BSON BinData type. Index keys that are of the BinData type are more efficiently stored in the index if: the binary subtype value is in the range of 0-7 or 128-135, and the length of the byte array is: 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, or 32.

我的 UUID 在那个范围内,所以性能会比 String 表示有所提高。