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

Query glibc version only once to speed up JSTransformer on Linux #9117

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/transformers/js/src/JSTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,14 +939,16 @@ export default (new Transformer({
// also load the native module on the main thread, so that it is not unloaded until process exit.
// See https://github.com/rust-lang/rust/issues/91979.
let isLoadedOnMainThread = false;

// $FlowFixMe
let {glibcVersionRuntime} = process.report.getReport().header;

async function loadOnMainThreadIfNeeded() {
if (
!isLoadedOnMainThread &&
Copy link
Member

Choose a reason for hiding this comment

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

hmm it's surprising to me that this is running more than once per thread given this check here. any idea why that's happening?

Copy link
Contributor Author

@pastelsky pastelsky Jul 2, 2023

Choose a reason for hiding this comment

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

isLoadedOnMainThread is set to true only if the legacy glibc version condition is met —

if (glibcVersionRuntime && parseFloat(glibcVersionRuntime) <= 2.17) {
let api = WorkerFarm.getWorkerApi();
await api.callMaster({
location: __dirname + '/loadNative.js',
args: [],
});
isLoadedOnMainThread = true;

Else, its called once per transform —

async transform({asset, config, options, logger}) {
let [code, originalMap] = await Promise.all([
asset.getBuffer(),
asset.getMap(),
init,
loadOnMainThreadIfNeeded(),
]);

I think moving the check outside might be better in that case?

    if (glibcVersionRuntime && parseFloat(glibcVersionRuntime) <= 2.17) {
      let api = WorkerFarm.getWorkerApi();
      await api.callMaster({
        location: __dirname + '/loadNative.js',
        args: [],
      });
    }

   isLoadedOnMainThread = true;

Copy link
Member

Choose a reason for hiding this comment

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

Ah right

process.platform === 'linux' &&
WorkerFarm.isWorker()
) {
// $FlowFixMe
let {glibcVersionRuntime} = process.report.getReport().header;
if (glibcVersionRuntime && parseFloat(glibcVersionRuntime) <= 2.17) {
let api = WorkerFarm.getWorkerApi();
await api.callMaster({
Expand Down