Repository navigation
Description
RecommendationFinder is used in several places to produce "Did you mean...?" suggestions when variables or keywords are not found. It performs fuzzy string matching over all candidates, which is O(n×m) per lookup.
Affected locations
robot.variables.notfound.variable_not_found()— iterates over all variable candidatesrobot.running.namespace.KeywordRecommendationFinder— iterates over all keywords from all libraries and resources (also affects--dryrun, sinceKeywordRunnerpassesrecommend_on_failure=Trueby default)
(A third location in parsing.lexer.settings operates on a small fixed set of setting names, so it is not a performance concern.)
Note that there is already a TODO comment in
robotframework/src/robot/running/namespace.py
Line 250 in 1121a9b
| # TODO: Consider changing the default value of `recommend_on_failure` to False. |
For tools that use Robot Framework's variable resolution programmatically (e.g., IDE language servers, static analysis tools, like RobotCode ), variable_not_found() may be triggered thousands of times during analysis. In large projects with many variables, this becomes a critical bottleneck.
Real-world impact: Analyzing 375 Robot Framework files took over 30 minutes, with the vast majority of time spent in RecommendationFinder. After monkey-patching variable_not_found to skip recommendations, the same analysis completes in under a minute. See: robotcodedev/robotcode#587
The KeywordRecommendationFinder in namespace.py has the same O(n×m) characteristic, though it primarily affects runtime execution and --dryrun rather than static analysis. RobotCode does not use RF's runtime namespace for keyword resolution, so this is not triggered in our case, but other tools or --dryrun with many missing keywords could be affected.
Current workaround
In RobotCode, we now monkey-patch variable_not_found across all modules that import it (robot.variables.notfound, finders, evaluation, store, robot.variables) to replace it with a version that simply raises VariableError without calling RecommendationFinder. This works, but it's fragile — it depends on internal module structure and could break with any refactoring of the robot.variables package.
Suggestion
A simple global flag like RECOMMENDATIONS_ENABLED (e.g., on RecommendationFinder or in robot.utils.recommendations) that can be set to False to skip all fuzzy matching would be sufficient and avoid the need for monkey-patching.
Activity
pekkaklarck commentedon Mar 31, 2026
Let's at least change the default value of
recommend_on_failuretoFalse. We obviously need to turn it toTruein certain cases during execution to get those helpful recommendations. If that affects also programmatic usage where recommendations aren't needed, we need to make it somehow configurable. An environment variable feels a bit icky, but it certainly is an option if there are no better alternatives.MikeAckerschott commentedon Apr 1, 2026
Hello, OOP here from the robotcode issue. Ive found that applying the monkeypatch before running robot like this:
Does significantly speed up test execution time compared to running robot normally within the CLI. I also checked the performance with cProfile and found that for my test 187 / 196 seconds of runtime is spend within the variable_not_found function:
After finding out about this, i did migrate some of the variables to python variable files which did seem to reduce the variable_not_found cumulative time
pekkaklarck commentedon Apr 1, 2026
@MikeAckerschott, do I get it right that
RecommendationFindercauses performance issues for you also during normal execution, not only with RobotCode? That sounds a bit strange, because it should only be used in cases where keywords, variables, etc. aren't found and that shouldn't happen too often during normal execution. It's certainly possible that there's a bug in Robot's code that causes that to happen too often, though. We've had such bug earlier as #4659 and #5051 demonstrate.Could you create a simple example demonstrating the problem so that I can test it locally? That would massively help pinpointing where the problem is and hopefully fixing it.
MikeAckerschott commentedon Apr 1, 2026
Yes, RecommendationFinder seems to be causing performance issues during normal execution using robot in the commandline. Ill try to see if i can create a reproducible scenario without sharing any of the company's code base. This might take a bit as im not exactly sure what triggers the RecommendationFinder
MikeAckerschott commentedon Apr 1, 2026
Ive changed my variable_not_found function to the following to easily see when it triggers:
A robotfile like this seems to trigger the added logging, but the test still passes, so the variables do get resolved when the VariableError is caught:
changing my variables section to this:
Has the same logging:
Removing the brackets from the value of variable1 like this:
${variable1: int} 1, removes the[ WARN ] Variable '${1}' not found.warning.Then trying to change my variables like this:
Causes the test to fail as it is interpreting the value as a string:
Is there a defined best practice for declaring variables based on the value of other variables? im reading through the docs but cant find any information about that
MikeAckerschott commentedon Apr 1, 2026
If i follow the creating dictionaries example from chapter 2.6.3 , the ReccomendationFinder also gets triggered:
pekkaklarck commentedon Apr 1, 2026
Thanks for the examples! This seems to occur when variables are resolved and they aren't found directly.
${variable1+1}most likely triggers this because there's no variable with exactly that name, because this actually uses the extended variable syntax and there's only${variable1}.${1}most likely triggers this because there's no such pre-defined variable, but numbers are handled separately. I need to investigate this more closely, but I don't have time for that right now. My guess is that in these cases we just shouldn't look for recommendations. Instead of disabling them in these cases I believe we should disable them by default and only ask for them when we actually need them.MikeAckerschott commentedon Apr 1, 2026
I agree. I do find the RecommendationFinder useful but practically it only presents the recommendation to the user if the VariableError is not resolved successfully and the test fails due to it. The many other calls to RecommendationFinder slow down tests drastically when a codebase has many variables, which the codebase i work in has.
d-biehl commentedon Apr 1, 2026
I’d actually been thinking of using a global variable at module level to disable this, but I think the problem is actually a bit more complex than that...
pekkaklarck commentedon Apr 16, 2026
I investigated variable related issues and my earlier guess why this occurs seems to be accurate. When Robot searches for any variable, it uses different variable finders to see is it
${1}),${EMPTY},${{['a', 'b']}}),%{HOME}), or${var + 1}).As you can see from the code, these are always attempted in the above order. That means that with each variable Robot first tries to see is the a variable with that name. If there isn't, the resulting error message contains recommendations, but in this particular case the whole error message is ignored. This makes no sense and needs to be changed.
While investigating this, I noticed some other stupidity with the related code as well. I'll commit changes related to that shorty and will continue to investigate and fix the recommendation related issue later.
pekkaklarck commentedon Apr 16, 2026
Fixing the variable finding related problem will help in normal usage as well as in programmatic usage. It may not be enough for the programmatic usage, though, and we can look at other alternatives as well. Adding an environment variable like
ROBOT_NO_RECOMMENDATIONSthat would disable all keyword and variable recommendations could be one solution. Let's anyway see what's the situation is once I got the issue discussed above fixed first.Refactor variable finding
Enhance variable resolving performance
pekkaklarck commentedon Apr 17, 2026
The above commit ought to most of the problems with variable resolving performance. I tested that on my machine the following dummy test runs in ~1.25s with RF 7.4.2 but takes only ~0.75s with the latest code. That's a pathological example where variable resolving really dominates, but I noticed that Robot's own acceptance tests got a bit faster as well.
Can you @d-biehl and @MikeAckerschott test the latest code and report how it works? Based on your findings we can then decide should we do something else like adding that
ROBOT_NO_RECOMMENDATIONSenvironment variable. I believe we should anyway concentrate on variable resolving performance in this issue and submit separate issues about other possible fixes/enhancements.Enhance performance of reporting non-existing variables
[-]`RecommendationFinder` causes severe performance issues for programmatic use[/-][+]Performance regression in resolving variables[/+]pekkaklarck commentedon Apr 17, 2026
I changed the title of this issue to cover only variable resolving. Unless more regressions are found, or the changes that are already don't have an effect, I think this issue can be closed. I'm open for making it possible to disable recommendations altogether with an environment variable, but that should then get its own issue.
pekkaklarck commentedon Apr 27, 2026
There have been no comments lately and performance of resolving variables has been enhanced heavily. I consider this issue done, but it can be reopened if there's more to do variables. Other topics discussed as part of this issue nevertheless require their own issues if we want to address them.