{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/25270","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/25270/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/25270/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/25270/events","html_url":"https://github.com/dart-lang/sdk/issues/25270","id":122403297,"number":25270,"title":"Compile ng2 change checks down to !==","user":{"login":"yjbanov","id":211513,"avatar_url":"https://avatars.githubusercontent.com/u/211513?v=3","gravatar_id":"","url":"https://api.github.com/users/yjbanov","html_url":"https://github.com/yjbanov","followers_url":"https://api.github.com/users/yjbanov/followers","following_url":"https://api.github.com/users/yjbanov/following{/other_user}","gists_url":"https://api.github.com/users/yjbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/yjbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjbanov/subscriptions","organizations_url":"https://api.github.com/users/yjbanov/orgs","repos_url":"https://api.github.com/users/yjbanov/repos","events_url":"https://api.github.com/users/yjbanov/events{/privacy}","received_events_url":"https://api.github.com/users/yjbanov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-dart2js","name":"area-dart2js","color":"c7def8"},{"url":"https://api.github.com/repos/dart-lang/sdk/labels/dart2js-optimization","name":"dart2js-optimization","color":"d4c5f9"},{"url":"https://api.github.com/repos/dart-lang/sdk/labels/Priority-Medium","name":"Priority-Medium","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-16T00:59:58Z","updated_at":"2015-12-17T21:45:01Z","closed_at":null,"body":"Due to a difference in the way Dart VM and JS perform `String` comparison (see https://github.com/dart-lang/sdk/issues/22496) Angular checks for object identity using the following function:\r\n\r\n```dart\r\nbool looseIdentical(a, b) =>\r\n    a is String && b is String ? a == b : identical(a, b);\r\n```\r\n\r\nThis way both Dartium and Chrome behave the same. However, in JS you already get this behavior for free using the `===` operator. The code above results in the following:\r\n\r\n```dart\r\n    looseIdentical: [function(a, b) {\r\n      return typeof a === \"string\" && typeof b === \"string\" ? J.$eq$(a, b) : a == null ? b == null : a === b;\r\n    }\r\n\r\n    // myriads of calls like this one are generated from people's templates:\r\n    if (!Q.looseIdentical(l_foo0, this.foo0)) {\r\n      this.dispatcher.notifyOnBinding$2(...);\r\n      this.foo0 = l_foo0;\r\n    }\r\n```\r\n\r\nWe are paying the cost of two function calls and a type check before we get to `===`. I'd rather see the whole thing inlined and reduced to:\r\n\r\n```dart\r\n    if (l_foo0 !== this.foo0) {\r\n      this.dispatcher.notifyOnBinding$2(...);\r\n      this.foo0 = l_foo0;\r\n    }\r\n```\r\n\r\n## Attempt to trick dart2js\r\n\r\nTrick by @sigmundch:\r\n\r\n```dart\r\nconst _IS_DART_VM = !identical(1.0, 1);\r\nbool looseIdentical(a, b) => _IS_DART_VM\r\n    ? a is String && b is String ? a == b : identical(a, b)\r\n    : identical(a, b);\r\n```\r\n\r\nResults in the following:\r\n\r\n```dart\r\n    looseIdentical: function(a, b) {\r\n      var t1 = a == null ? b == null : a === b;\r\n      return t1;\r\n    }\r\n```\r\n\r\nSlightly better, but still costing a function call and a conditional expression before we get to `===`.\r\n\r\nHow can we get it down to just `!==`? These comparisons are done by change detectors which are on the performance hot path.\r\n"},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/165591111","html_url":"https://github.com/dart-lang/sdk/issues/25270#issuecomment-165591111","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/25270","id":165591111,"user":{"login":"yjbanov","id":211513,"avatar_url":"https://avatars.githubusercontent.com/u/211513?v=3","gravatar_id":"","url":"https://api.github.com/users/yjbanov","html_url":"https://github.com/yjbanov","followers_url":"https://api.github.com/users/yjbanov/followers","following_url":"https://api.github.com/users/yjbanov/following{/other_user}","gists_url":"https://api.github.com/users/yjbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/yjbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjbanov/subscriptions","organizations_url":"https://api.github.com/users/yjbanov/orgs","repos_url":"https://api.github.com/users/yjbanov/repos","events_url":"https://api.github.com/users/yjbanov/events{/privacy}","received_events_url":"https://api.github.com/users/yjbanov/received_events","type":"User","site_admin":false},"created_at":"2015-12-17T21:45:01Z","updated_at":"2015-12-17T21:45:01Z","body":"Idea: would it be possible to tweak Dart VM to match JS `===` semantics in Dartium (and _only_ in Dartium)? After all, all debugging that's happening in Dartium ends up compiled to JS anyway."}}