[SERVER-40444] IndexCatalogEntry should expose NamespaceString to avoid type conversion/allocation in AbstractIndexAccessMethod Created: 02/Apr/19  Updated: 29/Oct/23  Resolved: 04/Apr/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.1.10

Type: Improvement Priority: Major - P3
Reporter: Henrik Edin Assignee: Henrik Edin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-32709 Mobile SE: Index creation takes a lon... Closed
Backwards Compatibility: Fully Compatible
Sprint: Dev Tools 2019-04-08
Participants:

 Description   

When inserting documents we create a new NamespaceString from a std::string const& causing a memory allocation. One allocation per document and index combination (also affecting insertMany). The NamespaceString is then used to query the ReplicationCoordinator where it does not need to store or keep the NamespaceString making the memory allocation above unnecessary.

This especially affects performance in mobile/embedded where we most likely are single threaded.

Partial callstack when running insertMany:

mongoed.exe!mongo::AbstractIndexAccessMethod::shouldCheckIndexKeySize(mongo::OperationContext * opCtx) Line 150	C++
mongoed.exe!mongo::AbstractIndexAccessMethod::insertKeys(mongo::OperationContext * opCtx, const std::set<mongo::BSONObj,mongo::BSONComparatorInterfaceBase<mongo::BSONObj>::LessThan,std::allocator<mongo::BSONObj> > & keys, const std::set<mongo::BSONObj,mongo::BSONComparatorInterfaceBase<mongo::BSONObj>::LessThan,std::allocator<mongo::BSONObj> > & multikeyMetadataKeys, const std::vector<std::set<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64> >,std::allocator<std::set<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64> > > > & multikeyPaths, const mongo::RecordId & loc, const mongo::InsertDeleteOptions & options, mongo::InsertResult * result) Line 201	C++
mongoed.exe!mongo::AbstractIndexAccessMethod::insert(mongo::OperationContext * opCtx, const mongo::BSONObj & obj, const mongo::RecordId & loc, const mongo::InsertDeleteOptions & options, mongo::InsertResult * result) Line 191	C++
mongoed.exe!mongo::IndexCatalogImpl::_indexFilteredRecords(mongo::OperationContext * opCtx, mongo::IndexCatalogEntry * index, const std::vector<mongo::BsonRecord,std::allocator<mongo::BsonRecord> > & bsonRecords, __int64 * keysInsertedOut) Line 1196	C++
mongoed.exe!mongo::IndexCatalogImpl::_indexRecords(mongo::OperationContext * opCtx, mongo::IndexCatalogEntry * index, const std::vector<mongo::BsonRecord,std::allocator<mongo::BsonRecord> > & bsonRecords, __int64 * keysInsertedOut) Line 1216	C++
mongoed.exe!mongo::IndexCatalogImpl::indexRecords(mongo::OperationContext * opCtx, const std::vector<mongo::BsonRecord,std::allocator<mongo::BsonRecord> > & bsonRecords, __int64 * keysInsertedOut) Line 1285	C++
mongoed.exe!mongo::CollectionImpl::_insertDocuments(mongo::OperationContext * opCtx, std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<mongo::InsertStatement> > > begin, std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<mongo::InsertStatement> > > end, mongo::OpDebug * opDebug) Line 541	C++
mongoed.exe!mongo::CollectionImpl::insertDocuments(mongo::OperationContext * opCtx, std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<mongo::InsertStatement> > > begin, std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<mongo::InsertStatement> > > end, mongo::OpDebug * opDebug, bool fromMigrate) Line 400	C++
mongoed.exe!mongo::`anonymous namespace'::insertDocuments(mongo::OperationContext * opCtx, mongo::Collection * collection, std::_Vector_iterator<std::_Vector_val<std::_Simple_types<mongo::InsertStatement> > > begin, std::_Vector_iterator<std::_Vector_val<std::_Simple_types<mongo::InsertStatement> > > end, bool fromMigrate) Line 353	C++
mongoed.exe!mongo::`anonymous namespace'::insertBatchAndHandleErrors(mongo::OperationContext * opCtx, const mongo::write_ops::Insert & wholeOp, std::vector<mongo::InsertStatement,std::allocator<mongo::InsertStatement> > & batch, mongo::`anonymous-namespace'::LastOpFixer * lastOpFixer, mongo::WriteResult * out, bool fromMigrate) Line 420	C++
mongoed.exe!mongo::performInserts(mongo::OperationContext * opCtx, const mongo::write_ops::Insert & wholeOp, bool fromMigrate) Line 572	C++
mongoed.exe!mongo::`anonymous namespace'::CmdInsert::Invocation::runImpl(mongo::OperationContext * opCtx, mongo::BSONObjBuilder & result) Line 300	C++



 Comments   
Comment by Githook User [ 03/Apr/19 ]

Author:

{'name': 'Henrik Edin', 'username': 'henrikedin', 'email': 'henrik.edin@mongodb.com'}

Message: SERVER-40444 IndexCatalogEntry to use NamespaceString instead of plain string. This avoids converting between types later on.
Branch: master
https://github.com/mongodb/mongo/commit/b63457c9e8597a6704b0fb015d827425585a5bef

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