I have used the JQL function module quite a lot in my plugin, JQL Tricks. It is a really useful plugin module to extend JIRA's search capabilities and works well for most cases.
But with the growing list of enterprise customers, performance has become a great problem. After introducing many improvements to the new JQL functions, there still a bottleneck which appears to be coming from IssueIdValidator.
The problem comes when the return type is ISSUE. It is very convinient as it lets users search with clauses like "issue in .." but SearchService adds a lot of load in such cases because of the extra validations. For example, if a query returns 40K issues, IssueIdValidator verifies that each of the issue id is a valid one. This extra validation is sometimes totally useless because permissions are already checked once. But there is no way to override it as pe the current architecture
This is completely unrelated to JQL Tricks or any other plugin as I reproduced the same issue with a simple plugin where I used the following query directly in issue navigator and in a simple JQL function that returns issues matching the same. The time taken to return the result using the JQL function is a lot more than the direct usage.
To make sure, I have added profile logs in the code and here is the result.
Out of the 33017ms, the plugin code takes only 2513ms. Attached is the code used in the test plugin. You can reproduce the numbers in a test instance with a large number of issues.
There should be a way to either skip the validation or do is faster.