Skip to content

Imported libraries should not be cached #2106

Description

@pekkaklarck

Currently we put imported libraries into an internal cache to avoid importing and processing them multiple times. It's questionable how much time that actually saves and there's a risk that we waste memory keeping references to libraries used only once. The cache also makes the overall import logic more complicated and causes bugs like #2105. Need to measure what kind of performance changes removing the cache would have.

We are also thinking about not caching resources (#2099) and variable files (#2101).

Activity

  1. added this to the 3.0 milestone on Aug 14, 2015
  2. changed the title [-]Imported libraries should be cached[/-] [+]Imported libraries should not be cached[/+] on Aug 14, 2015
  3. yahman72 commented on Oct 9, 2015

    @yahman72
    Contributor

    This would be clearer indeed but could break things (triggered by #2165) - some things to consider :

    1. use cache when imported with Library KW in *** Settings ***?
    2. optionally use cache when imported with BuiltIn.Import Library KW (e.g. with force_reimport=False arg?

    I have for example many resource files with possible duplicate imports Libs e.g.
    a) MyRes_A uses My_Lib_1 and MyRes_C
    b) MyRes_B uses MyRes_C
    c) MyRes_C uses My_Lib_1

    Scenario a) would import My_Lib_1 twice. This could become problematic if the My_Lib_1 is stateful and is imported with BuiltIn.Import Library

  4. stasiek commented on Nov 19, 2015

    @stasiek

    How about some flag-parameter for Library to make sure the import is fresh?
    Like
    Library SwingLibrary FRESH

  5. pekkaklarck commented on Nov 19, 2015

    @pekkaklarck
    MemberAuthor

    I would rather have a solution that works out-of-the-box and doesn't require uses to know some special flag. Another problem is that libraries themselves can accept arguments and they can conflict with such special flags. We already have WITH NAME flag, but I would like to limit them only to cases where we really need them.

  6. modified the milestone: 3.0 on Dec 7, 2015
  7. pekkaklarck commented on Feb 4, 2017

    @pekkaklarck
    MemberAuthor

    #2377 contains a related request to allow importing different libraries using same name. Need to think about these together.

  8. pekkaklarck commented on Oct 3, 2018

    @pekkaklarck
    MemberAuthor

    #2931 is also somewhat related. It was closed because we already have this issue.

  9. added this to the v3.2 milestone on Aug 15, 2019
  10. pekkaklarck commented on Aug 15, 2019

    @pekkaklarck
    MemberAuthor

    #3249 demonstrates another problem caused by library cache. Let's try to get this fixed in RF 3.2.

  11. pekkaklarck commented on Aug 15, 2019

    @pekkaklarck
    MemberAuthor

    Should also look at #2377 when implementing this.

  12. pekkaklarck commented on Nov 8, 2019

    @pekkaklarck
    MemberAuthor

    RF 3.2 is so long overdue that this is unfortunately descoped. If someone would really like this in, please comment here.

  13. modified the milestones: v3.2, v3.3 on Nov 8, 2019
  14. modified the milestones: v3.3, v4.0 on Feb 7, 2020
  15. removed this from the v5.0 milestone on Sep 24, 2021
  16. pekkaklarck commented on Sep 24, 2021

    @pekkaklarck
    MemberAuthor

    Removed from RF 5.0 scope simply because there are so many other more important enhancements. Another reason is that there probably aren't other changes that would affect the related code. Better to have a release where one of the main topics is enhancing importing and storing libraries as well as resource and variable files.

  17. tauzahmd commented on Jul 15, 2022

    @tauzahmd

    I was having a similar issue with the importing of libraries. Ideally when a class is imported as Library it will call __init__ and supply the argument to it if any. But if it is already imported with similar arguments it will not reimport instead it takes from cache.
     

    Now if the ROBOT_LIBRARY_SCOPE = 'GLOBAL' I would agree that the library can be cached, but if the scope has been changed 'SUITE'or TEST it should import the library again irrespective of whether it is caches or not for suites or test respectively.
     

    For my case I wanted the import to happen for each robot file in a folder, even though I had set the scope of library to SUITE. It was taking it from cache and so __init__ was never called.

    Is this the current expected behavior? If yes I would argue that this should be brought to the release scope so it does not takes from cache and takes into account the library's scope.

  18. added this to the v8.0 milestone on Mar 14, 2024
  19. franzhaas commented on Jan 21, 2025

    @franzhaas
    Contributor

    This is somewhat linked to this topic as well.: #5122 however this is just a documentation clarification... much less impact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions