Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Conversation

AlexanderSher
Copy link
Contributor

No description provided.


_unknownType = new PythonType("Unknown", new Location(_moduleResolution.BuiltinsModule), string.Empty);
_builtinTypes[BuiltinTypeId.Unknown] = _unknownType;
return _unknownType;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unknown type switched to lazy initialization

/// <remarks>New in 2.2, moved in 3.3</remarks>
private static List<PythonLibraryPath> GetDefaultSearchPaths(IFileSystem fs, string library) {
var result = new List<PythonLibraryPath>();
private static ImmutableArray<PythonLibraryPath> GetDefaultSearchPaths(IFileSystem fs, string library) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely related to this PR, but I feel like we should come up with some agreement about which list types we're going to use across the board so we don't end up switching them back and forth between PRs...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK either way but I tend to use interfaces on public surface. Is there a benefit of Immutable over IReadOnly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 issues with IReadOnlyList<T>:

  1. It is read-only, but not immutable. If an object is provided to the outer context, but owner still has a reference to the object, the is no way to synchronize it anymore. E.g.:
    private List<SomeType> _someList;
    public IReadOnlyList<SomeType> SomeList=> _someList;
    If any code gets reference to the list through SomeList, it still can be changed by the owner, concurrently to the reader.
  2. Adding elements. With ImmutableArray, adding elements create new instance of it, but it is as cheap as adding to List<T>. For IReadOnlyList<T>, it requires to create a copy of the list.
  3. Enumerator. For any interface, enumerator is an object. For ImmutableArray<T> and List<T> it would be a struct. This becomes a problem when we have foreach loops in analysis where enumerators are promoted to Gen2.

@jakebailey
Copy link
Member

When I do the same memory testing I did for #1402, the memory usage after a big session or a reload doesn't seem to go down very much (or at all), and requires something else to happen to do another GC/compact for the memory to go down again. Maybe there's some timing problem where the new code is a bit faster and things aren't ready to be compacted yet, or something, but it might hurt memory usage. (Another case #1428 would help.)

@jakebailey
Copy link
Member

jakebailey commented Aug 29, 2019

Just an example of what I'm describing:

image

  1. pip install numpy, reloads, memory goes up.
  2. pip install -e . (small package, no imports), reloads and redoes everything, memory is the same.
  3. pip unintsall numpy, memory usage goes down, but not all the way.
  4. pip uninstall mypackage, memory usage goes down to the baseline.

There are variations where the initial install doesn't drop after its session GC/compact, and some where the reload GC/compact doesn't have any affect either.

@jakebailey
Copy link
Member

jakebailey commented Aug 30, 2019

Here's what happens when I repeat the above but modify the ForceGC function to wait a bit:

image

private static void ForceGCIfNeeded(ILogger logger, int originalRemaining, int remaining, bool force) {
    if (force || originalRemaining - remaining > 1000) {
        Task.Run(async () => {
            await Task.Delay(500);
            logger?.Log(TraceEventType.Verbose, "Forcing full garbage collection and heap compaction.");
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            GC.Collect();
        }).DoNotWait();
    }
}

@MikhailArkhipov MikhailArkhipov merged commit c33774d into microsoft:master Aug 30, 2019
@AlexanderSher AlexanderSher deleted the Fix1156 branch August 30, 2019 20:27
jakebailey pushed a commit to jakebailey/python-language-server that referenced this pull request Nov 1, 2019
…ad (microsoft#1496)

* Fix microsoft#1156: Unresolved import for builtin packages after reload

* Address CR comments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants