[SERVER-55043] canonicalizeBSONType() should be implemented as a lookup table Created: 08/Mar/21  Updated: 29/Oct/23  Resolved: 14/Jan/22

Status: Closed
Project: Core Server
Component/s: Internal Code, Performance
Affects Version/s: None
Fix Version/s: 5.3.0

Type: Improvement Priority: Major - P3
Reporter: Mathias Stearn Assignee: Jordi Olivares Provencio
Resolution: Fixed Votes: 0
Labels: neweng, newgrad
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File canonBsonType.patch    
Backwards Compatibility: Fully Compatible
Sprint: Execution Team 2021-03-22, Execution Team 2022-01-10, Execution Team 2022-01-24
Participants:

 Description   

I noticed it was showing up as hot in some profiles. Making it a lookup table makes it basically disappear. I'm attaching a patch for how I did it.

It may make sense to move the table construction out of line (I don't know if we are ever getting any benefit from calling this on a known-constant value), but the lookup should probably stay inline since it is just 2-3 instructions (possibly compute the address of the table using rip-relative addressing, sign extend the type, do the lookup). Canonicalizing 2 types (as is usually done) takes only 5 instructions because the actual table address only needs to be computed once.



 Comments   
Comment by Githook User [ 14/Jan/22 ]

Author:

{'name': 'Jordi Olivares Provencio', 'email': 'jordi.olivares-provencio@mongodb.com', 'username': 'jordiolivares'}

Message: SERVER-55043 Implement canonicalizeBSONType as a lookup table
Branch: master
https://github.com/mongodb/mongo/commit/2e26b975e18359c17fd6e0537b69938ef4c75310

Comment by Mathias Stearn [ 09/Mar/21 ]

I replaced the patch with a cleaner one. It does all indexing with uint8_t so it generates equally good code without needing to work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99470

Generated at Thu Feb 08 05:35:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.