Closed Bug 1342025 Opened 4 years ago Closed 4 years ago

browser-ctrlTab.js calls ctrlTab.updatePreview too frequently for TabAttrModified events

Categories

(Firefox :: Tabbed Browser, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 55
Tracking Status
firefox55 --- fixed

People

(Reporter: dao, Assigned: milindl, Mentored)

References

Details

(Keywords: good-first-bug, perf, Whiteboard: [good first bug][lang=js])

Attachments

(1 file)

See https://hg.mozilla.org/mozilla-central/annotate/0eef1d5a39366059677c6d7944cfe8a97265a011/browser/base/content/browser-ctrlTab.js#l475

We only care about certain attributes there, namely "label", "busy", "image" and "selected". These days TabAttrModified gets dispatched for more tab attributes that this code doesn't really care about, thus it should detect these cases. This can be done by looking at event.detail.changed, which is an array of the names of the attributes that changed.
Note that the feature implemented by this code is disabled by default and can be enabled in about:preferences#general ("Ctrl+Tab cycles through tabs in recently used order").
Keywords: perf
Mentor: dao+bmo
Hey Dao is anybody currently working on this bug? I'm in a class at my university and this seems like a bug we'd like to dig around in and try to fix. If I'm understanding this correctly the function updatePreview is being called on too many attribute tags and you want this reduced to only label, busy, image, and selected tags?
(In reply to jason r from comment #2)
> Hey Dao is anybody currently working on this bug?

No, not yet.

> I'm in a class at my
> university and this seems like a bug we'd like to dig around in and try to
> fix. If I'm understanding this correctly the function updatePreview is being
> called on too many attribute tags and you want this reduced to only label,
> busy, image, and selected tags?

Exactly!
Jason, do you still intend to work on this?
Flags: needinfo?(renaudjj)
Hello Dao, I am new to Open Source Development. Is it possible for me to work on this?
(In reply to Nitish from comment #5)
> Hello Dao, I am new to Open Source Development. Is it possible for me to
> work on this?

Since we haven't heard from Jason in more than a week, please go ahead.
Flags: needinfo?(renaudjj)
Attachment #8843689 - Flags: review?(dao+bmo)
Hi, I'm also new to contributing here.
I have tried to fix this bug to the best of my capabilities.
I started on this yesterday, without noticing Nitish's comment, but I've sent him a mail so
we can collaborate on this, like the "How to submit patches" guide says.

Thanks
Comment on attachment 8843689 [details]
Bug 1342025 - reduce calls to ctrlTab.updatePreview

https://reviewboard.mozilla.org/r/117290/#review118952

Looks good apart from some minor issues...

::: browser/base/content/browser-ctrlTab.js:478
(Diff revision 1)
>          this._initRecentlyUsedTabs();
>          break;
>        case "TabAttrModified":
> -        // tab attribute modified (e.g. label, busy, image, selected)
> +        // tab attribute modified (i.e. label, busy, image, selected)
> +	// update preview only if tab attribute modified in the list
> +	if (["label", "busy", "image", "selected"].reduce(

Please use 'some' instead of 'reduce'

::: browser/base/content/browser-ctrlTab.js:479
(Diff revision 1)
>          break;
>        case "TabAttrModified":
> -        // tab attribute modified (e.g. label, busy, image, selected)
> +        // tab attribute modified (i.e. label, busy, image, selected)
> +	// update preview only if tab attribute modified in the list
> +	if (["label", "busy", "image", "selected"].reduce(
> +	    (res, elem) => res || (event.detail.changed.indexOf(elem) !== -1),

Please use 'includes' instead of 'indexOf'

::: browser/base/content/browser-ctrlTab.js:481
(Diff revision 1)
> -        // tab attribute modified (e.g. label, busy, image, selected)
> +        // tab attribute modified (i.e. label, busy, image, selected)
> +	// update preview only if tab attribute modified in the list
> +	if (["label", "busy", "image", "selected"].reduce(
> +	    (res, elem) => res || (event.detail.changed.indexOf(elem) !== -1),
> +	    false)) {
> -        for (let i = this.previews.length - 1; i >= 0; i--) {
> +            for (let i = this.previews.length - 1; i >= 0; i--) {

Intentation is off by two spaces
Attachment #8843689 - Flags: review?(dao+bmo) → review-
Comment on attachment 8843689 [details]
Bug 1342025 - reduce calls to ctrlTab.updatePreview

https://reviewboard.mozilla.org/r/117288/#review118954
I have made the changes, I think it should be OK now
Thanks
Comment on attachment 8843689 [details]
Bug 1342025 - reduce calls to ctrlTab.updatePreview

https://reviewboard.mozilla.org/r/117290/#review119122

Looks good!
Attachment #8843689 - Flags: review?(dao+bmo) → review+
Pushed by dgottwald@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/17b068bfce7c
reduce calls to ctrlTab.updatePreview. r=dao
https://hg.mozilla.org/mozilla-central/rev/17b068bfce7c
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 55
Assignee: nobody → i.milind.luthra
Filed a followup: bug 1345773
Blocks: 1345773
You need to log in before you can comment on or make changes to this bug.