Skip to content

GetLocatedImports uses quadratic amount of memory in KnownTargets at startup #4317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mpickering opened this issue Jun 13, 2024 · 0 comments · Fixed by #4318
Closed

GetLocatedImports uses quadratic amount of memory in KnownTargets at startup #4317

mpickering opened this issue Jun 13, 2024 · 0 comments · Fixed by #4318
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@mpickering
Copy link
Contributor

At startup GetLocatedImports is called on all known files. Say you have 10000 modules in your project then this leads to 10000 calls to GetLocatedImports running concurrently.

In GetLocatedImports the known targets are consulted and the targetsMap is created by mapping the known targets. This map
is used for introducing sharing amongst filepaths. This operation copies a local copy of the target map which is local to the rule.

let targetsMap = HMap.mapWithKey const targets

So now each rule has a hashmap of size 10000 held locally to it and depending on how the threads are scheduled there will be
10000^2 elements in total allocated in hashmaps. This used a lot of memory.

Solution: Return the normalising map in the result of the GetKnownTargets rule so it is shared across threads.

@mpickering mpickering added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. status: needs triage labels Jun 13, 2024
mpickering added a commit that referenced this issue Jun 13, 2024
At startup `GetLocatedImports` is called on all known files. Say you
have 10000 modules in your project then this leads to 10000 calls to
GetLocatedImports running concurrently.

In `GetLocatedImports` the known targets are consulted and the
targetsMap is created by mapping the known targets. This map is used for
introducing sharing amongst filepaths.  This operation copies a local
copy of the `target` map which is local to the rule.

```
let targetsMap = HMap.mapWithKey const targets
```

So now each rule has a hashmap of size 10000 held locally to it and
depending on how the threads are scheduled there will be 10000^2
elements in total allocated in hashmaps. This used a lot of memory.

Solution: Return the normalising map in the result of the
`GetKnownTargets` rule so it is shared across threads.

Fixes #4317
fendor pushed a commit that referenced this issue Jun 13, 2024
At startup `GetLocatedImports` is called on all known files. Say you
have 10000 modules in your project then this leads to 10000 calls to
GetLocatedImports running concurrently.

In `GetLocatedImports` the known targets are consulted and the
targetsMap is created by mapping the known targets. This map is used for
introducing sharing amongst filepaths.  This operation copies a local
copy of the `target` map which is local to the rule.

```
let targetsMap = HMap.mapWithKey const targets
```

So now each rule has a hashmap of size 10000 held locally to it and
depending on how the threads are scheduled there will be 10000^2
elements in total allocated in hashmaps. This used a lot of memory.

Solution: Return the normalising map in the result of the
`GetKnownTargets` rule so it is shared across threads.

Fixes #4317
fendor pushed a commit that referenced this issue Jun 13, 2024
At startup `GetLocatedImports` is called on all known files. Say you
have 10000 modules in your project then this leads to 10000 calls to
GetLocatedImports running concurrently.

In `GetLocatedImports` the known targets are consulted and the
targetsMap is created by mapping the known targets. This map is used for
introducing sharing amongst filepaths.  This operation copies a local
copy of the `target` map which is local to the rule.

```
let targetsMap = HMap.mapWithKey const targets
```

So now each rule has a hashmap of size 10000 held locally to it and
depending on how the threads are scheduled there will be 10000^2
elements in total allocated in hashmaps. This used a lot of memory.

Solution: Return the normalising map in the result of the
`GetKnownTargets` rule so it is shared across threads.

Fixes #4317
michaelpj pushed a commit that referenced this issue Jun 13, 2024
At startup `GetLocatedImports` is called on all known files. Say you
have 10000 modules in your project then this leads to 10000 calls to
GetLocatedImports running concurrently.

In `GetLocatedImports` the known targets are consulted and the
targetsMap is created by mapping the known targets. This map is used for
introducing sharing amongst filepaths.  This operation copies a local
copy of the `target` map which is local to the rule.

```
let targetsMap = HMap.mapWithKey const targets
```

So now each rule has a hashmap of size 10000 held locally to it and
depending on how the threads are scheduled there will be 10000^2
elements in total allocated in hashmaps. This used a lot of memory.

Solution: Return the normalising map in the result of the
`GetKnownTargets` rule so it is shared across threads.

Fixes #4317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant