Skip to content
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
Copy Markdown
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?

@pastelsky pastelsky Jul 2, 2023

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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