botbuilder-python icon indicating copy to clipboard operation
botbuilder-python copied to clipboard

port: Add top level lazy load on LanguageGeneratorManager (#6123)

Open github-actions[bot] opened this issue 4 years ago • 0 comments

The changes in Add top level lazy load on LanguageGeneratorManager (#6123) may need to be ported to maintain parity with microsoft/botbuilder-dotnet.

Fixes #6116

Description

  • Implements lazy loading of lg files to reduce cold startup. LG files are now loaded and cached as needed throughout the bot usage and not all at startup time.
  • LG files that contain exports are always loaded on startup since they can be accessed anywhere (customers should try to avoid using too many exports to reduce cold startup.
  • Added type caching to InterfaceConverter to ensure types are instantiated only once while loading the root dialog and dependencies when the bot starts
  • Removed loadOnConstructor parameter from LanguageGeneratorManager and TemplateEngineLanguageGenerator constructors. Lazy instances are used across the board when posible and there is no option to override this (it is not necessary).

Additional details

We tested this code against some test bots to measure the startup time and here are the results:

Bot Startup time with 4.15.1 Startup time with optimizations Notes
74 dialogs, 7 languages ~32 secs ~7 secs Higher startup time compared to others due to 35 files using @exports (5 dialogs in 7 languages)
24 dialogs, 3 languages ~2 mins 20 secs ~2 secs Bot doesn't use the @exports lg feature
141 dialogs, 3 languages > 1 hr 30 mins ~9.5 secs Bot doesn't use the @exports lg feature

Performance improves drastically because of these changes, however, number of dialogs and extensively use of '@exports` will continue to affect bot's cold start.

Breaking changes

This PR introduces some minor breaking changes that should not impact composer bots that haven't been customized, customized bots will be impacted only if they used any of the following methods and properties:

  • Removed loadOnConstructor parameter from TemplateEngineLanguageGenerator constructor
  • Removed loadOnConstructor parameter from LanguageGeneratorManager constructor
  • LanguageGeneratorManager.LanguageGenerators property type was changed from ConcurrentDictionary<string, LanguageGenerator> to ConcurrentDictionary<string, Lazy<LanguageGenerator>> and the property is now read only.
  • MultiLanguageGenerator.LanguageGenerators property type was changed from ConcurrentDictionary<string, LanguageGenerator> to ConcurrentDictionary<string, Lazy<LanguageGenerator>> and the property is now read only.
  • MultiLanguageGeneratorBase.TryGetGenerator(DialogContext dialogContext, string locale, out LanguageGenerator generator) method signature was changed to MultiLanguageGeneratorBase.TryGetGenerator(DialogContext dialogContext, string locale, out Lazy<LanguageGenerator> generator). The classes that derive from it have been updated accordingly.

Please review and, if necessary, port the changes.

github-actions[bot] avatar Jan 26 '22 17:01 github-actions[bot]