[SERVER-71968] Investigate impact of invariants and tasserts on performance Created: 08/Dec/22  Updated: 29/Oct/23  Resolved: 09/Mar/23

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

Type: Task Priority: Major - P3
Reporter: Mihai Andrei Assignee: Ivan Fefer
Resolution: Fixed Votes: 0
Labels: pm2697-m3
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-73173 Replace invariant with tassert in src... Backlog
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Sprint: QE 2022-12-12, QE 2022-12-26, QE 2023-01-09, QE 2023-01-23, QE 2023-02-06, QE 2023-02-20, QE 2023-03-06, QE 2023-03-20
Participants:
Story Points: 5

 Description   

This ticket tracks the work to investigate whether invariants/tasserts slow down SBE plan execution and if so, figuring out how to mitigate their impact.



 Comments   
Comment by Ivan Fefer [ 09/Mar/23 ]

There are some ~5% performance gains to be found in replacing tasserts and invariants with dasserts, but given that this may lead to undefined behavior in production and there are other performance improvements to be done, I think this change is not worth it in my opinion. I am closing this ticket.

Comment by Githook User [ 10/Feb/23 ]

Author:

{'name': 'Ivan Fefer', 'email': 'ivan.fefer@mongodb.com', 'username': 'Fefer-Ivan'}

Message: SERVER-71968 Make MONGO_SOURCE_LOCATION static constexpr in tassert
Branch: master
https://github.com/mongodb/mongo/commit/eb74202c608550490a603fa31ad8a46f2a92932f

Comment by Ivan Fefer [ 09/Feb/23 ]

There is also an issue with invariants with messages. They pass a lambda that converts an error message into std::string into a function (usually inlined) that does the check. 

This also triggers stack-protector. We can fix it by replacing the function with a macro, but the problem is that the function template, used in invariant is overloaded for Status and similar objects, which is impossible to do in a macro and will require more work. 

Given that invariants with messages are pretty rare, I think we can ignore that.

Comment by Ivan Fefer [ 09/Feb/23 ]

Fixing triggering stack-protector via tassert gives ~5% performance on different workloads.
And when looking on disassembled code, with this fix tassert == invariant where there is no error.
This fix is currently in code review.

Comment by Ivan Fefer [ 08/Feb/23 ]

Macro for tassert creates extra local variable, that may lead to introduction of stack protector in functions that otherwise won't have it. 
Doesn't sound too bad, but may accumulate to a lot of extra instructions. 
Made a patch to avoid it. Let's see how it affects perf: https://spruce.mongodb.com/version/63e3af042fbabe5ba22265b6/tasks

Comment by Zixuan Zhuang [ 12/Dec/22 ]

https://spruce.mongodb.com/version/638fd1530305b96c6851878d/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC

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