microsoft / botbuilder-dotnet

Welcome to the Bot Framework SDK for .NET repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using .NET.
https://github.com/Microsoft/botframework
MIT License
872 stars 479 forks source link

Use LRUCache in ExpressionParser for efficient memory usage #6667

Closed InfinytRam closed 1 year ago

InfinytRam commented 1 year ago

Fixes #6656

Description

This PR addresses a memory leak issue in the ExpressionParser class. Previously, the ExpressionParser class used a ConcurrentDictionary to cache parsed expressions, which could lead to excessive memory usage over time. This PR changes the ExpressionParser class to use an LRUCache instead, which has a maximum capacity and uses a least-recently-used policy to evict entries from the cache when the maximum capacity is reached. This change should help to mitigate the memory leak issue.

Specific Changes

Testing

This change was tested using a console application that demonstrates the memory leak issue in ExpressionParser: https://github.com/jamesemann/expression-parser-leak

Before:

After: