Skip to content

SelectControlValueAccessor.compareWith: 25 tests for 5 options seems excessive #19723

Closed

Description

@pamtbaau

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When using compareWith on a <select> with only 5 options, compareWith function is being called 25 times.

On initialization of the form, 15 runs are tested against undefined, 5 against null and 5 against an object.

On refresh of the option list, 25 runs are tested against an object in a peculiar order.

This happens both in development and production.

Expected behavior

I would expect it to test between 1 and max. 5 times depending on the selected option

Minimal reproduction of the problem with instructions

demo plunker See console for output.

What is the motivation / use case for changing the behavior?

Performance

Environment


Angular version: 4.4.5


Browser:
- [x] Chrome (desktop) version 61.0.3163.100 (Official Build) (64-bit)
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
- [x] Electron version 1.7.8

For Tooling issues:
- Node version:  v8.5.0 
- Platform:  Windows 10  

Others:

Activity

  1. Toxicable commented on Oct 14, 2017

    @Toxicable

    I don't see an issue here, remember that in debug mode all CD is run twice, so in prod mode you'd only see 12 or 13 calls

  2. pamtbaau commented on Oct 14, 2017

    @pamtbaau
    Author

    The numbers mentioned were taken from the plunker in production mode...

    I'm puzzled... Are 12 or 13 calls to compare an id against a list of 5 really to be expected???

    Would you consider the following outcome where compareWith is run 5 times over the entire set of options after a data refresh and skipping successful hits as being a non-issue?

    After initialization of view
    
    comparing: id 1 with id undefined
    comparing: id 1 with id undefined
    comparing: id 2 with id undefined
    comparing: id 1 with id undefined
    comparing: id 2 with id undefined
    comparing: id 3 with id undefined
    comparing: id 1 with id undefined
    comparing: id 2 with id undefined
    comparing: id 3 with id undefined
    comparing: id 4 with id undefined
    comparing: id 1 with id undefined
    comparing: id 2 with id undefined
    comparing: id 3 with id undefined
    comparing: id 4 with id undefined
    comparing: id 5 with id undefined
    comparing: id 1 with id null
    comparing: id 2 with id null
    comparing: id 3 with id null
    comparing: id 4 with id null
    comparing: id 5 with id null
    comparing: id 1 with id 5
    comparing: id 2 with id 5
    comparing: id 3 with id 5
    comparing: id 4 with id 5
    comparing: id 5 with id 5 -> true
    
    Refresh data
    
    comparing: id 2 with id 5
    comparing: id 3 with id 5
    comparing: id 4 with id 5
    comparing: id 5 with id 5 -> true
    comparing: id 3 with id 5
    comparing: id 4 with id 5
    comparing: id 5 with id 5 -> true
    comparing: id 4 with id 5
    comparing: id 5 with id 5 -> true
    comparing: id 5 with id 5 -> true
    comparing: id 1 with id 5
    comparing: id 1 with id 5
    comparing: id 2 with id 5
    comparing: id 1 with id 5
    comparing: id 2 with id 5
    comparing: id 3 with id 5
    comparing: id 1 with id 5
    comparing: id 2 with id 5
    comparing: id 3 with id 5
    comparing: id 4 with id 5
    comparing: id 1 with id 5
    comparing: id 2 with id 5
    comparing: id 3 with id 5
    comparing: id 4 with id 5
    comparing: id 5 with id 5 -> true
    
  3. kara commented on Dec 5, 2017

    @kara
    Contributor

    We should probably take a closer look and see if all these calls are needed or if there's a more efficient way to do this.

  4. added this to the Backlog milestone on Jan 24, 2018
  5. added
    P4
    and removed on Oct 1, 2020
  6. AndrewKushnir commented on Mar 23, 2021

    @AndrewKushnir
    Contributor

    FYI, closing this ticket in favor of #41330, which has more up-to-date repro.

  7. angular-automatic-lock-bot commented on Apr 23, 2021

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area: formsfreq2: mediumrefactoring

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions