[SERVER-66053] Use StringSet instead of std::set in getModifiedPaths Created: 28/Apr/22  Updated: 29/Oct/23  Resolved: 14/Jul/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0

Type: Task Priority: Minor - P4
Reporter: David Percy Assignee: Matt Olma
Resolution: Fixed Votes: 0
Labels: greenerbuild
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Sprint: QO 2023-07-10, QO 2023-07-24
Participants:

 Description   

If we change `std::set<std::string> paths` () to `StringSet paths`, there are a couple benefits:

  • It uses a hash table instead of a tree.
  • It supports queries like `.count(StringData)`, whereas std::set<std::string> only supports `.count(std::string const&)`, which can require making a copy if you only have a StringData.

However this assumes we don't care about the order of elements in this set. It looks like we are iterating over this set in a few places, which may or may not mean the order matters. For example if we only union/intersect this with other sets, and check membership, then order doesn't matter.

Whoever takes this will need to check whether the order matters or not.



 Comments   
Comment by Githook User [ 14/Jul/23 ]

Author:

{'name': 'mattsimply', 'email': '67564577+mattsimply@users.noreply.github.com', 'username': 'mattsimply'}

Message: SERVER-66053: enable heterogeneous lookup in OrderedPathSet
Branch: master
https://github.com/mongodb/mongo/commit/30273c762a2e83d38f97445e5ddf129f7e13a437

Comment by David Percy [ 10/Jul/23 ]

matt.olma@mongodb.com found some uses that rely on the order, so I guess we can't switch to a hash table.

But we can still make sure it's using heterogenous lookup. We're already using a custom comparator, so I think we can just change the comparator to take 'StringData' instead of 'const std::string&'. Then the comparator will work with any combination of std::string / StringData arguments, and so inserts and queries on the map won't make any temporary strings.

Generated at Thu Feb 08 06:04:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.