Skip to content

refactored insertIntoIndexHTML#151

Merged
kratiahuja merged 1 commit intoember-fastboot:masterfrom
bekzod:refactor-insert-html
Jun 10, 2017
Merged

refactored insertIntoIndexHTML#151
kratiahuja merged 1 commit intoember-fastboot:masterfrom
bekzod:refactor-insert-html

Conversation

@bekzod
Copy link
Copy Markdown
Contributor

@bekzod bekzod commented Jun 6, 2017

No description provided.

Comment thread src/result.js Outdated
if (body) {
let isBodyReplaced = false;
html = html.replace("<!-- EMBER_CLI_FASTBOOT_BODY -->", function() {
html = html.replace(/<\!-- EMBER_CLI_FASTBOOT_(HEAD|BODY) -->/g, function(match, p1) {
Copy link
Copy Markdown
Contributor

@kratiahuja kratiahuja Jun 9, 2017

Choose a reason for hiding this comment

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

My two cents:

I really find the changes here convoluted and the head and body fork is at two places instead of one - making readability hard. I am not convinced this is improving readability if that is what the motivation of the changes was.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

motivation is was improve performance :P, one .replace is better than .replaces, simple benchmark I used https://gist.github.com/bekzod/f08628db3cbbbd678bbc8f72e4b01001 , readability-wise I would say it is same level as before at least it uses less lines of code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By how much was the performance improved?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

before change: 370ms
after change: 193ms

so 50%

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

at least on my machine (mac os node v6.8.1)

Comment thread src/result.js Outdated
if (body) {
let isBodyReplaced = false;
html = html.replace("<!-- EMBER_CLI_FASTBOOT_BODY -->", function() {
html = html.replace(/<\!-- EMBER_CLI_FASTBOOT_(HEAD|BODY) -->/g, function(match, p1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we use a better variable than p1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/result.js
if (!isHeadReplaced) {
return missingTag('<!--EMBER_CLI_FASTBOTT_HEAD-->');
}
if (head && !isHeadReplaced) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why check for head and body here? Seems unecessary since it defaults to empty string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/bekzod/fastboot/blob/45087528437aa0d1c2dc620b9a45898a8063ce1a/src/result.js#L37-L39 because sometimes missing head insert comment tag is still valid, the same logic was used before, if I remove head bunch of test are broken

Copy link
Copy Markdown
Contributor

@kratiahuja kratiahuja Jun 10, 2017

Choose a reason for hiding this comment

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

But body will always be present. It seems an unecessary check. But I am fine either ways

@bekzod bekzod force-pushed the refactor-insert-html branch from 4508752 to d238901 Compare June 10, 2017 01:38
@kratiahuja kratiahuja merged commit c5175b4 into ember-fastboot:master Jun 10, 2017
@bekzod bekzod deleted the refactor-insert-html branch June 10, 2017 01:47
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.

2 participants