Skip to content

perf(analyze): Targeted caching optimization#574

Open
Lakitna wants to merge 3 commits intorobotcodedev:mainfrom
Lakitna:performance/cache-pure-utility-functions
Open

perf(analyze): Targeted caching optimization#574
Lakitna wants to merge 3 commits intorobotcodedev:mainfrom
Lakitna:performance/cache-pure-utility-functions

Conversation

@Lakitna
Copy link

@Lakitna Lakitna commented Feb 25, 2026

After our discussion at Robocon I was curious what takes the most time in Robotcode.

During profiling I came across 2 situations that significantly slowed down code analysis in my ~600 file project.

same_file() took significant time. After slapping a functools.lru_cache on it, my runtime went down with about 8 minutes!
from: Files: 650, Errors: 1403, Warnings: 13, Infos: 552, Hints: 2709 (in 11m 0.14s)
to: Files: 650, Errors: 1403, Warnings: 13, Infos: 552, Hints: 2709 (in 2m 55.07s)

search_variable() wasn't as big a time sink, but I knew that this project contains a lot of global vars. According to robotunused it contains 31102 non-local variables. So the old cache limit of 1024 seemed small to me. After upping it significantly to 100.000, it runs 37 seconds faster.
from: Files: 650, Errors: 1403, Warnings: 13, Infos: 552, Hints: 2709 (in 2m 55.07s)
to: Files: 650, Errors: 1403, Warnings: 13, Infos: 552, Hints: 2709 (in 2m 18.07s)

These are some nice time savings for such small changes.

@d-biehl I did consider memory footprint too. Do you think it makes sense to add a cache size config thing? Or maybe replace lru_cache with something more sophisticated and more configurable?

This saves about 8 minutes (11m 0.14s -> 2m 55.07) in my test project of ~600 files.
This saves about 37 seconds (2m 55.07 -> 2m 18.07) in my test project of ~600 files.
@Lakitna Lakitna force-pushed the performance/cache-pure-utility-functions branch from 81f64e7 to 8194326 Compare February 25, 2026 15:37
@Lakitna Lakitna changed the title Performance - Targeted caching changes to pure functions perf(analyze) Targeted caching changes to pure functions Feb 25, 2026
@Lakitna Lakitna changed the title perf(analyze) Targeted caching changes to pure functions perf(analyze): Targeted caching optimization Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant