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

perf(es): Don't share Globals #5975

Merged
merged 15 commits into from Sep 28, 2022
Merged

perf(es): Don't share Globals #5975

merged 15 commits into from Sep 28, 2022

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Sep 28, 2022

Description:

We don't need to share one instance of Globals.


Investigation of test failure

Added log:

  DEBUG  ===== Before pure =====
"use strict";
function _checkPrivateRedeclaration(obj, privateCollection) {
    if (privateCollection.has(obj)) {
        throw new TypeError("Cannot initialize the same private elements twice on an object");
    }
}
function _classApplyDescriptorGet(receiver, descriptor) {
    if (descriptor.get) {
        return descriptor.get.call(receiver);
    }
    return descriptor.value;
}
function _classExtractFieldDescriptor(receiver, privateMap, action) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to " + action + " private field on non-instance");
    }
    return privateMap.get(receiver);
}
function _classPrivateFieldGet(receiver, privateMap) {
    var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
    return _classApplyDescriptorGet(receiver, descriptor);
}
function _classPrivateFieldInit(obj, privateMap, value) {
    _checkPrivateRedeclaration(obj, privateMap);
    privateMap.set(obj, value);
}
var foo = "bar";
var _bar = new WeakMap();
class Foo {
    test() {
        return _classPrivateFieldGet(this, _bar);
    }
    constructor(){
        _classPrivateFieldInit(this, _bar, {
            writable: true,
            value: foo
        });
    }
}
const f = new Foo;
expect(f.test()).toBe(foo);
expect("bar" in f).toBe(false);

===== After pure =====
"use strict";
function _checkPrivateRedeclaration(obj, privateCollection) {
    if (privateCollection.has(obj)) {
        throw new TypeError("Cannot initialize the same private elements twice on an object");
    }
}
function _classApplyDescriptorGet(receiver, descriptor) {
    if (descriptor.get) {
        return descriptor.get.call(receiver);
    }
    return descriptor.value;
}
function _classExtractFieldDescriptor(receiver, privateMap, action) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to " + action + " private field on non-instance");
    }
    return privateMap.get(receiver);
}
function _classPrivateFieldGet(receiver, privateMap) {
    var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
    return _classApplyDescriptorGet(receiver, descriptor);
}
function _classPrivateFieldInit(obj, privateMap, value) {}
var foo = "bar";
var _bar = new WeakMap();
class Foo {
    test() {
        return _classPrivateFieldGet(this, _bar);
    }
    constructor(){
        _classPrivateFieldInit(this, _bar, {
            writable: true,
            value: foo
        });
    }
}
const f = new Foo;
expect(f.test()).toBe(foo);
expect("bar" in f).toBe(false);

and I found


  DEBUG  ignore_return_value: Dropping a pure call, kind: "change"
    at crates/swc_ecma_minifier/src/compress/pure/misc.rs:662
    in visit_mut_fn_decl with id: _classPrivateFieldInit#5
    in apply pure optimizer
    in optimize with pass: 1
    in compress ast
    in minify
    in process_js_inner
    in process_js_with_custom_pass
    in process_js_file with fm: SourceFile(/Users/kdy1/projects/s/issues/crates/swc/tests/babel-exec/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/exec.js)
    in test_file with idx: 12

too

So I think the BytePos for pure comment is wrong, due to misusage of BytePos

@kdy1 kdy1 added this to the Planned milestone Sep 28, 2022
@kdy1 kdy1 self-assigned this Sep 28, 2022
@kdy1 kdy1 marked this pull request as ready for review September 28, 2022 06:16
@kdy1 kdy1 enabled auto-merge (squash) September 28, 2022 06:16
kodiakhq[bot]
kodiakhq bot previously approved these changes Sep 28, 2022
Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

swc-bump:

  • swc_common
  • swc --breaking

Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

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

Automated review comment generated by auto-rebase script

kodiakhq[bot]
kodiakhq bot previously approved these changes Sep 28, 2022
kodiakhq[bot]
kodiakhq bot previously approved these changes Sep 28, 2022
@kdy1 kdy1 disabled auto-merge September 28, 2022 08:14
@kdy1 kdy1 marked this pull request as draft September 28, 2022 08:14
@kdy1 kdy1 marked this pull request as ready for review September 28, 2022 08:47
kodiakhq[bot]
kodiakhq bot previously approved these changes Sep 28, 2022
@kdy1 kdy1 enabled auto-merge (squash) September 28, 2022 08:47
kodiakhq[bot]
kodiakhq bot previously approved these changes Sep 28, 2022
Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

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

Automated review comment generated by auto-rebase script

@kdy1 kdy1 merged commit 19131e1 into swc-project:main Sep 28, 2022
@kdy1 kdy1 deleted the perf-lock branch September 28, 2022 10:34
@kdy1 kdy1 modified the milestones: Planned, v1.3.4 Sep 30, 2022
finnboeger added a commit to finnboeger/swc that referenced this pull request Oct 4, 2022
finnboeger added a commit to finnboeger/swc that referenced this pull request Oct 4, 2022
@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants