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

ChartView: update code for list-rendering #513

Merged

Conversation

chel-seyy
Copy link
Contributor

@chel-seyy chel-seyy commented Jan 25, 2019

During list rendering, `v-for` is used with `v-if` which can increase
the file processing time, due to additional checks.

Let's follow the vue style guide[1] by replacing these instances with
computed properties, where necessary. Data is only updated when
changed, instead of being generated every time.

[1]: Vue style guide for avoiding use of v-if with for
https://vuejs.org/v2/style-guide/#Avoid-v-if-with-v-for-essential

@chel-seyy
Copy link
Contributor Author

@reposense/devs Ready for review

@chel-seyy chel-seyy removed the c.Bug label Jan 25, 2019
Copy link
Member

@eugenepeh eugenepeh left a comment

Choose a reason for hiding this comment

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

Just a hypothesis, let me know if its not possible:

Currently, it seems that scripting takes a long time (hiding java file from Eugene in reposense_RepoSense_master)
image

Whereas collapsing and expanding all files are less computational intensive
image

Of course, given the amount of processing difference, there's definitely a difference.
However my point is, whenever the selectedFiles or files in this PR changes, it will trigger the code view to be reload which will create a lot of scripting tasks. So my question is, can we bypass the reload, using less processing power to produce same result by doing something similar to collapsing and expanding the files (just hiding the file content and header from the code view)?

@chel-seyy
Copy link
Contributor Author

chel-seyy commented Jan 26, 2019

Tried implementing your suggestion by hiding the files using v-show which uses CSS-based toggling so data will remain in the DOM. However, it seems to lag more. :/

After some searching, storing selectedFiles inside computed properties seems to be a better option. selectedFiles will be cached and only recomputed when user selects/deselects checkboxes. This can improve the efficiency of the filtering files process.

Also, Vuejs discourages v-for and v-if used together (current implementation), as this is more inefficient and alike to mapping that iterates through every file for checking.

https://vuejs.org/v2/style-guide/#Avoid-v-if-with-v-for-essential

@eugenepeh
Copy link
Member

I see, great work for trying out alternatives.

Also, Vuejs discourages v-for and v-if used together (current implementation), as this is more inefficient and alike to mapping that iterates through every file for checking.

In that case, could multiple vue instances be the causation of the crash in #451?

@chel-seyy
Copy link
Contributor Author

In that case, could multiple vue instances be the causation of the crash in #451?

There are certainly some examples of v-if used with v-for, but these are inside the v-summary instance:

.summary-charts(v-for="repo of filtered", v-if="repo.length>0")

v-for="(slice, j) in user.commits",
v-if="slice.insertions>0",

Hence, they are not directly related to the crashing of the download feature. Perhaps I can open an issue about this, to improve vue's efficiency?


On my side, I have changed the files rendering to use computed properties. However, I noticed that using computed properties does not speed up the selection process significantly. In fact, if v-for is used with v-if (current implementation), the processing is actually faster.

I can push these latest changes up for you to compare the speed difference.

@eugenepeh
Copy link
Member

Yes, it seems to be slower after each iteration and eventually crashed on the 4th.

image
image
image

@yong24s
Copy link
Contributor

yong24s commented Jan 29, 2019

Can try to move the following code-block out of updated()?

The crash seems to be caused by vuejs going into an endless update.

document.querySelectorAll('pre.hljs code').forEach((ele) => {
window.hljs.highlightBlock(ele);
});

Call it only when code view is open for a new author?

It seems that the above code-block also tries to highlight code of other users as well 🤔.

@yong24s
Copy link
Contributor

yong24s commented Jan 29, 2019

I have removed highlightjs and its really fast now.
Test site: https://yong24s.github.io/RepoSense

@yamidark
Copy link
Contributor

I have removed highlightjs and its really fast now.

Nice, tested and barely feel any lag right now 👍.

@yong24s
Copy link
Contributor

yong24s commented Jan 29, 2019

Nice, tested and barely feel any lag right now 👍.

But I haven't find out which variable to watch to invoke the hightlightjs 😅

@yong24s
Copy link
Contributor

yong24s commented Jan 29, 2019

If you toggle code views of different contribution, highlightjs will render after the first.

Even updated() has been removed https://github.com/yong24s/RepoSense/blob/gh-pages/static/js/v_authorship.js, probably because the code is in <pre><code> 🤔

@yong24s
Copy link
Contributor

yong24s commented Jan 29, 2019

My attempt to fix the lag, with comments: yong24s@141a8e6

Test-site: https://yong24s.github.io/RepoSense

Need help to make hljs rendering consistent. Now you may need to click twice to get it to work. 😅

@eugenepeh
Copy link
Member

I have removed highlightjs and its really fast now.

highlightjs is meant to give context to the code... without that it is much harder to make sense out of jumbled codes.

@yong24s
Copy link
Contributor

yong24s commented Jan 29, 2019

highlightjs is meant to give context to the code... without that it is much harder to make sense out of jumbled codes.

I meant to say I moved hljs out of the Vue#updated. 😓

@chel-seyy
Copy link
Contributor Author

chel-seyy commented Jan 30, 2019

@yong24s By "hljs rendering" problems, do you mean the toggling of hidden (or non-authored) code?
Because from the test-site preview, the highlighting seemed to work, except for the toggling.

@yong24s
Copy link
Contributor

yong24s commented Jan 30, 2019

@yong24s By "hljs rendering" problems, do you mean the toggling of hidden (or non-authored) code?
Because from the test-site preview, the highlighting seemed to work, except for the toggling.

It don't always work in the code view. I'm not sure where to best put the hljs code 😅.

@ongspxm
Copy link
Contributor

ongspxm commented Jan 30, 2019

It don't always work in the code view. I'm not sure where to best put the hljs code 😅

one other way is to wrap the whole code thing into a component of its own and put the hljs inside the component, so one call will just be in charge of one "file"

@yong24s
Copy link
Contributor

yong24s commented Jan 31, 2019

@chelseyong

You want to work on the hljs optimization? I can create a new issue and assign it to you.

Let this PR be code view optimization only.

@chel-seyy
Copy link
Contributor Author

@yong24s Okay can

@yamidark
Copy link
Contributor

Don't really see a different a response time when using the file type filter though.
Currently, hiding of the file types is very fast (almost instantaneous), but loading of the file types may take up some time (depending on the size).

From testing of Eugene in reposense_RepoSense_master (loading of file types):

Current master:
untitled

This PR:
untitled

Don't see much of a time difference between the two (and this PR actually may be slower!), and both still takes up a long time for scripting.
Can try to look into how we can speed up the loading time of file types?

Copy link
Contributor

@yamidark yamidark left a comment

Choose a reason for hiding this comment

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

Changes requested as above

@chel-seyy
Copy link
Contributor Author

chel-seyy commented Feb 23, 2019

@yamidark Okay, do you mean the scripting in the loading of tab?
image

@yamidark
Copy link
Contributor

@yamidark Okay, do you mean the scripting in the loading of tab?

Nope, I meant the loading of all the files in the code panel, when after we hide all the files types and re-show them (uncheck and check the All box), which is supposed to be what this PR is working on right (according to the title)?
untitled

@chel-seyy
Copy link
Contributor Author

Noted, the message was not clear before.

@yamidark
Copy link
Contributor

@chelseyong Well if you could improve the time for initial loading of all the codeview files as well, that will be good too 😄

Copy link
Member

@eugenepeh eugenepeh left a comment

Choose a reason for hiding this comment

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

hmm now that speed isn't much of an issue, perhaps focus on cleaning up?

@chel-seyy
Copy link
Contributor Author

@eugenepeh Okay. May I know what do you refer to as cleaning up?

@eugenepeh
Copy link
Member

@eugenepeh Okay. May I know what do you refer to as cleaning up?

just pretty much whatever you're doing now, following suggestion given in https://vuejs.org/v2/style-guide etc.

Let us know when you're done.

@chel-seyy
Copy link
Contributor Author

@eugenepeh PR is ready

Copy link
Contributor

@yamidark yamidark left a comment

Choose a reason for hiding this comment

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

@chelseyong Remember to update the PR title and message since this PR objective change to that of cleaning up code

@chel-seyy chel-seyy changed the title [#485][Code view] Improve file type filter response time [#485] Change the code for list-rendering Feb 25, 2019
@chel-seyy chel-seyy changed the title [#485] Change the code for list-rendering Change the code for list-rendering Feb 25, 2019
Copy link
Contributor

@yong24s yong24s left a comment

Choose a reason for hiding this comment

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

Nice work by following best practices. 👍

@yamidark
Copy link
Contributor

Slight nits to proposed message:

During list rendering, `v-for` is used with `v-if` which can increase
the file processing time, due to additional checks.

Let's follow the vue style guide[1] by replacing these instances with
computed properties, where necessary. Data is only updated when
changed, instead of being generated every time.

[1]: Vue style guide for avoiding use of v-if with for
https://vuejs.org/v2/style-guide/#Avoid-v-if-with-v-for-essential

@chelseyong Do add 'footnotes' in your message for when you want to provide additional info through a link

@chel-seyy
Copy link
Contributor Author

@yamidark okay noted

@yamidark yamidark changed the title Change the code for list-rendering ChartView: update code for list-rendering Feb 27, 2019
@yamidark yamidark merged commit a9ac842 into reposense:master Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants