Skip to content
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

Simplify cpuCount utility and add limiting functionality #5673

Open
wants to merge 5 commits into
base: v2
Choose a base branch
from

Conversation

DeMoorJasper
Copy link
Member

↪️ Pull Request

This PR simplifies the cpuCount util to not check for real cores and just always use a maximal of half the threads that are available.

This shaves of 6ms startup time but mainly simplifies the logic a ton, making it more reliable across platforms.

Also added a limit parameter, that is set to 8 for now a that seems to be plenty for now (until we figure out which amount is perfect)

@height
Copy link

height bot commented Jan 16, 2021

Link Height tasks by mentioning a task ID in the pull request title or description, commit messages, or comments.

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@parcel-benchmark
Copy link

parcel-benchmark commented Jan 16, 2021

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 8.90s +34.00ms
Cached 492.00ms -25.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 610.00ms +40.00ms ⚠️
dist/legacy/index.76ce4b0c.js 1.12kb +0.00b 1.07s +452.00ms ⚠️
dist/modern/index.b43fcc94.js 1.12kb +0.00b 680.00ms -371.00ms 🚀
dist/legacy/index.html 701.00b +0.00b 586.00ms -30.00ms 🚀
dist/modern/index.html 701.00b +0.00b 680.00ms +108.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 59.00ms -11.00ms 🚀
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 76.00ms +7.00ms ⚠️
dist/legacy/index.76ce4b0c.js 1.12kb +0.00b 76.00ms +6.00ms ⚠️
dist/modern/index.b43fcc94.js 1.12kb +0.00b 79.00ms -12.00ms 🚀
dist/legacy/index.html 701.00b +0.00b 77.00ms +6.00ms ⚠️
dist/modern/index.html 701.00b +0.00b 76.00ms +6.00ms ⚠️
dist/legacy/index.44edca46.css 77.00b +0.00b 77.00ms +7.00ms ⚠️
dist/modern/index.0bc656bc.css 77.00b +0.00b 76.00ms +6.00ms ⚠️

React HackerNews ✅

Timings

Description Time Difference
Cold 25.64s -382.00ms
Cached 796.00ms +26.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/NotFound.f3269ae7.js 542.00b +0.00b 350.00ms +76.00ms ⚠️
dist/logo.24c8bf9e.png 274.00b +0.00b 146.00ms +23.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/index.js 477.78kb +0.00b 147.00ms +18.00ms ⚠️
dist/PermalinkedComment.0a19c7e4.js 4.24kb +0.00b 146.00ms +18.00ms ⚠️
dist/UserProfile.b2960402.js 1.78kb +0.00b 147.00ms +19.00ms ⚠️
dist/NotFound.f3269ae7.js 542.00b +0.00b 145.00ms +57.00ms ⚠️
dist/logo.24c8bf9e.png 274.00b +0.00b 110.00ms +19.00ms ⚠️

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 2.75m -5.32s
Cached 3.19s -7.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/index.59a13c6f.js 2.46mb +0.00b 1.16m -4.11s 🚀
dist/pdfRenderer.f5a3f4a7.js 1.11mb -6.00b 🚀 46.24s -506.00ms
dist/popup.119ff481.js 171.12kb +0.00b 21.02s -3.27s 🚀
dist/component.ad27194c.js 31.05kb +0.00b 2.17s -2.81s 🚀
dist/esm.e3419f0a.js 27.83kb +0.00b 11.54s +1.63s ⚠️
dist/DatePicker.faca45d0.js 21.38kb +0.00b 11.34s -771.00ms 🚀
dist/dropzone.3ae9a030.js 16.15kb +0.00b 15.23s -1.46s 🚀
dist/workerHasher.bc6346e1.js 11.90kb +0.00b 8.99s -1.57s 🚀
dist/component.677fad45.js 6.23kb +0.00b 4.55s -629.00ms 🚀
dist/EmojiPickerComponent.4991ddd4.js 3.68kb +0.00b 9.17s -2.44s 🚀
dist/Modal.08282ab6.js 3.23kb +0.00b 4.25s +2.89s ⚠️
dist/16.b6ca7fd0.js 2.50kb +0.00b 2.17s +802.00ms ⚠️
dist/feedback.facaac2e.js 1.87kb +0.00b 11.31s -764.00ms 🚀
dist/16.a9ea9b41.js 1.86kb +0.00b 5.42s -993.00ms 🚀
dist/browser.8883c452.js 1.85kb +0.00b 20.80s -1.57s 🚀
dist/16.89d45d15.js 1.80kb +0.00b 5.00s -780.00ms 🚀
dist/workerHasher.31326e89.js 1.77kb +0.00b 8.96s -1.57s 🚀
dist/status.6595d133.js 1.69kb +0.00b 6.13s -518.00ms 🚀
dist/code.efde0f48.js 1.61kb +0.00b 5.66s -1.04s 🚀
dist/heading6.5a6082c8.js 1.53kb +0.00b 6.28s -5.80s 🚀
dist/heading3.1c92891c.js 1.52kb +0.00b 6.28s -2.32s 🚀
dist/16.00f25203.js 1.47kb +0.00b 5.00s -633.00ms 🚀
dist/16.b7da7bde.js 1.45kb +0.00b 2.17s +802.00ms ⚠️
dist/heading5.88bc6249.js 1.41kb +0.00b 6.28s -2.35s 🚀
dist/expand.4a483eb0.js 1.39kb +0.00b 11.31s -776.00ms 🚀
dist/16.fa5f411c.js 1.36kb +0.00b 5.42s -994.00ms 🚀
dist/16.2a21d3f4.js 1.34kb +0.00b 2.17s +802.00ms ⚠️
dist/heading2.22de70fe.js 1.34kb +0.00b 6.28s -2.32s 🚀
dist/16.d10db5a3.js 1.32kb +0.00b 5.42s -459.00ms 🚀
dist/heading4.a2524c70.js 1.29kb +0.00b 6.28s -382.00ms 🚀
dist/16.9e97e787.js 1.28kb +0.00b 2.17s +802.00ms ⚠️
dist/component.233c7a65.js 1.26kb +0.00b 4.25s -702.00ms 🚀
dist/16.015dfb9d.js 1.26kb +0.00b 5.28s -553.00ms 🚀
dist/16.ec84a250.js 1.26kb +0.00b 5.00s -633.00ms 🚀
dist/quote.b6d8bffb.js 1.25kb +0.00b 6.13s -521.00ms 🚀
dist/action.01ec8983.js 1.24kb +0.00b 5.66s -783.00ms 🚀
dist/16.458399e0.js 1.23kb +0.00b 4.25s -702.00ms 🚀
dist/heading1.cc82b077.js 1.19kb +0.00b 7.17s +517.00ms ⚠️
dist/panel-error.7454ebc0.js 1.12kb +0.00b 6.80s +390.00ms ⚠️
dist/table.77df779b.js 1.10kb +0.00b 6.13s -518.00ms 🚀
dist/panel-success.d5752da0.js 1.06kb +0.00b 6.80s +389.00ms ⚠️
dist/panel-note.6a71a1f2.js 1.05kb +0.00b 6.80s +390.00ms ⚠️
dist/media-picker-analytics-error-boundary.49b32f4d.js 1023.00b +0.00b 15.23s -1.46s 🚀
dist/media-card-analytics-error-boundary.b884d580.js 1019.00b +0.00b 20.64s -2.14s 🚀
dist/simpleHasher.79137cb4.js 767.00b +0.00b 8.96s -1.60s 🚀
dist/simpleHasher.2c5206fd.js 767.00b +0.00b 17.38s -7.03s 🚀
dist/index.html 119.00b +0.00b 2.77s -1.01s 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/index.59a13c6f.js 2.46mb -4.00b 🚀 620.00ms +18.00ms

Three.js ✅

Timings

Description Time Difference
Cold 21.34s +19.00ms
Cached 641.00ms +9.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@mischnic
Copy link
Member

I'll have to measure what the best number on an 4 core i5 without hyperthreading is....

@DeMoorJasper
Copy link
Member Author

@mischnic have you been able to test this yet?

@DeMoorJasper DeMoorJasper requested review from mischnic, devongovett and wbinnssmith and removed request for devongovett February 2, 2021 19:59
@mischnic
Copy link
Member

mischnic commented Feb 2, 2021

Windows 10, i5-4570 @ 3.20GHz (4 cores, 4 threads)

PARCEL_WORKERS: time
0: 2.18m
1: 2.06m
2: 1.52m
3: 1.26m
4: 1.30m
5: 1.32m

@DeMoorJasper
Copy link
Member Author

@mischnic So (cores - 1) for real cores and (threads / 2) when multithreaded or should it be (threads / 2 + 1).

Guess we can't really test the last idea unless someone has a 6 or 8 core processor device to test this on?

@mischnic
Copy link
Member

mischnic commented Feb 2, 2021

(I only did a single run, no averaging)

Honestly not sure if there's a benefit to changing the detection logic at all.

@DeMoorJasper
Copy link
Member Author

DeMoorJasper commented Feb 2, 2021

Originally I expected it to have a larger performance impact. But I wrote it anyway so created a PR, however I still see value in creating a simpler version that works regardless of os.

@DeMoorJasper DeMoorJasper deleted the simplify-cpu-count branch February 16, 2021 18:16
@aminya
Copy link
Contributor

aminya commented Mar 11, 2021

What happened to this PR? This does affect memory usage.

Should we merge the following instead?
#5617

@DeMoorJasper DeMoorJasper restored the simplify-cpu-count branch March 11, 2021 07:16
@DeMoorJasper DeMoorJasper reopened this Mar 11, 2021
@DeMoorJasper
Copy link
Member Author

@aminya I just closed it because it got kinda old without any approval. I reopened it in case anyone wants to merge it

Copy link
Contributor

@aminya aminya left a comment

Choose a reason for hiding this comment

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

I actually like the approach here. The overhead of calling external processes just to get the number of threads seems unnecessary to me.

Also, limiting the number of threads reduces memory usage.

let cachedCoreCount = 0;
const platform = os.platform();
export function getCoreCount(
limit: number = platform === 'win32' ? 4 : 8,
Copy link
Contributor

@aminya aminya Mar 16, 2021

Choose a reason for hiding this comment

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

This is not an OS-relevant issue. The parcel doesn't use the threads it spawns. Why do you want to create so many threads which Parcel doesn't use?

#5072 (comment)

Other than workers 0 and 1, the others almost do nothing.
image

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought this was a filesystem limitation of windows

Copy link
Contributor

Choose a reason for hiding this comment

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

That is a separate issue.

Copy link
Contributor

@aminya aminya Apr 29, 2021

Choose a reason for hiding this comment

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

Suggested change
limit: number = platform === 'win32' ? 4 : 8,
limit: number = 4,

Copy link
Contributor

@aminya aminya Apr 29, 2021

Choose a reason for hiding this comment

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

The smarter way is to spawn threads proportional to the work that Parcel wants to do. For example:

min((fileNumbers)/20, coresAvailable)

So, if there are 100 files and we have 16 cores, it will spawn only 5 cores.

Copy link
Member

@mischnic mischnic Apr 29, 2021

Choose a reason for hiding this comment

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

The smarter way is to spawn threads proportional to the work that Parcel wants to do. For example:

Yes, but we don't (always) know this beforehand.

Copy link
Contributor

@aminya aminya Apr 29, 2021

Choose a reason for hiding this comment

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

We should use the information when it is available. When not known, we can just use a constant:

min(fileNumbers ? (fileNumbers)/20 : 4, coresAvailable)

Copy link
Member

Choose a reason for hiding this comment

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

What is fileNumbers?
On an initial build (where there's the most work), we don't know.
For subsequent builds, we only know the filecount of the previous build, not how much changed (= how much work there is).

So I would say this isn't possible to know at all

Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe it is better to perform an initial analysis using all threads. Then after that, it can use a suitable number of workers for the actual build.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would probably slow it down more than it would speed up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants