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

refactor: hidden fields instead of internal fields #1478

Closed
wants to merge 7 commits into from

Conversation

ekashida
Copy link
Member

Details

Fixes #1299

Does this PR introduce breaking changes?

  • No, it does not introduce breaking changes.

@caridy
Copy link
Contributor

caridy commented Aug 27, 2019

So, I'm fine with this feature, but I think this will pose a perf regression, lets wait for the perf numbers.

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { defineProperty } from './language';
import { create, isUndefined } from './language';
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated to this pr: The fields util is replicated in 3 submodules(engine, synthetic-shadow, node-reactions). Is it a good time to pull it out as a shared library or submodule?
cc @caridy

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we have an issue for that

}
valuesByField[fieldName] = value;
}
: setInternalField; // Fall back to symbol based approach in compat mode
Copy link
Contributor

Choose a reason for hiding this comment

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

@ekashida #860 (comment)
To give your some context as to why we were falling back to symbol based approach in compat mode

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I didn't get the existing comment because it was actually falling back to the internal field approach (which was also based on symbols), which would fall back to the string-based approach.

@ekashida
Copy link
Member Author

@caridy @ravijayaramappa There were no comments from best, does that mean there was no perf regression? Also, any ideas why the perf tests require the vm to be set internally in vm.ts?

@@ -34,7 +34,7 @@ import {
getComponentAsString,
getTemplateReactiveObserver,
} from './component';
import { setInternalField, setHiddenField } from '../shared/fields';
import { setHiddenField, setInternalField } from '../shared/fields';
Copy link
Contributor

Choose a reason for hiding this comment

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

where is getInternalField used? I thought the idea was to remove that entirely.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I mentioned above that it was in vm.ts but it was actually in def.ts:

/**
 * EXPERIMENTAL: This function provides access to the component constructor,
 * given an HTMLElement. This API is subject to change or being removed.
 */
export function getComponentConstructor(elm: HTMLElement): ComponentConstructor | null {
    let ctor: ComponentConstructor | null = null;
    if (elm instanceof HTMLElement) {
        const vm = getInternalField(elm, ViewModelReflection);
        if (!isUndefined(vm)) {
            ctor = vm.def.ctor;
        }
    }
    return ctor;
}

I'm not sure why, but our perf tests blow up when we access the vm using getHiddenField here.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, let me look at it.

@ravijayaramappa
Copy link
Contributor

@ekashida I think BEST summary is posted only if there is a significant regression.
You can view the results by clicking on the Details link.
Screen Shot 2019-08-30 at 10 21 09 AM

@caridy
Copy link
Contributor

caridy commented Aug 30, 2019

No @ravijayaramappa it is indeed failing, I have tried in another PR:

Error: Benchmark parse error.
TypeError: Cannot read property 'id' of undefined
    at tmpl (http://127.0.0.1:38538/wc-append-1k.benchmark.js:9209:32)
    at evaluateTemplate (http://127.0.0.1:38538/wc-append-1k.benchmark.js:6804:27)
    at http://127.0.0.1:38538/wc-append-1k.benchmark.js:6934:20
    at ReactiveObserver.observe (http://127.0.0.1:38538/wc-append-1k.benchmark.js:5160:11)
    at vmBeingRendered (http://127.0.0.1:38538/wc-append-1k.benchmark.js:6932:16)
    at runWithBoundaryProtection (http://127.0.0.1:38538/wc-append-1k.benchmark.js:8442:9)
    at invokeComponentRenderMethod (http://127.0.0.1:38538/wc-append-1k.benchmark.js:6928:7)
    at renderComponent (http://127.0.0.1:38538/wc-append-1k.benchmark.js:7036:22)
    at rehydrate (http://127.0.0.1:38538/wc-append-1k.benchmark.js:8065:26)
    at rerenderVM (http://127.0.0.1:38538/wc-append-1k.benchmark.js:7967:7)
  ERROR     Error: Benchmark couldn't finish running. 
    at Socket.socket.on (/home/circleci/lwc/node_modules/@best/runner-hub/build/HubClient.js:84:24)
    at Socket.Emitter.emit (/home/circleci/lwc/node_modules/component-emitter/index.js:133:20)
    at Socket.onevent (/home/circleci/lwc/node_modules/socket.io-client/lib/socket.js:278:10)
    at Socket.onpacket (/home/circleci/lwc/node_modules/socket.io-client/lib/socket.js:236:12)
    at Manager.<anonymous> (/home/circleci/lwc/node_modules/component-bind/index.js:21:15)
    at Manager.Emitter.emit (/home/circleci/lwc/node_modules/component-emitter/index.js:133:20)
    at Manager.ondecoded (/home/circleci/lwc/node_modules/socket.io-client/lib/manager.js:345:8)
    at Decoder.<anonymous> (/home/circleci/lwc/node_modules/component-bind/index.js:21:15)
    at Decoder.Emitter.emit (/home/circleci/lwc/node_modules/component-emitter/index.js:133:20)
    at Decoder.add (/home/circleci/lwc/node_modules/socket.io-client/node_modules/socket.io-parser/index.js:251:12)
error Command failed with exit code 1.```

I will investigate.

@ekashida
Copy link
Member Author

#1485

@ekashida ekashida closed this Aug 31, 2019
@ekashida ekashida deleted the ekashida/fix-issue-1299 branch August 31, 2019 02:26
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.

[engine] refactor the way we store internal fields to use a weak map
3 participants