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

Remove redundant file writing #1090

Merged
merged 4 commits into from
Mar 23, 2020
Merged

Conversation

openorclose
Copy link
Contributor

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [ ] Enhancement to an existing feature

What is the rationale for this request?

It seems like there is an uneeded file write at

markbind/src/Page.js

Lines 799 to 802 in f4036cc

.then(result => markbinder.resolveBaseUrl(result, fileConfig))
.then(result => fs.outputFileAsync(this.tempPath, result))
.then(() => markbinder.renderFile(this.tempPath, fileConfig))
.then(result => this.postRender(result))

We should be able to just pass the string directly to renderFile

What changes did you make? (Give an overview)

Pass the string directly to renderFile

Provide some example code that this change will affect:

none

Is there anything you'd like reviewers to focus on?

Maybe there was a reason for the file write?

Testing instructions:

Proposed commit message: (wrap lines at 72 characters)

Remove redundant file writing

We are writing to a temp path, and then reading it immediately.

Let's avoid this by passing the string directly instead.

@acjh
Copy link
Contributor

acjh commented Mar 4, 2020

Maybe there was a reason for the file write?

Before #522, we had include and render commands, possibly to debug outputs.

@openorclose
Copy link
Contributor Author

Maybe there was a reason for the file write?

Before #522, we had include and render commands, possibly to debug outputs.

I see!

Since we don't have them now, should be ok to remove the file writing?

@acjh
Copy link
Contributor

acjh commented Mar 5, 2020

Yes. I wonder how much it improves build time.

src/Page.js Outdated
@@ -797,8 +797,7 @@ class Page {
.then(result => this.insertFooterFile(result))
.then(result => Page.insertTemporaryStyles(result))
.then(result => markbinder.resolveBaseUrl(result, fileConfig))
.then(result => fs.outputFileAsync(this.tempPath, result))
.then(() => markbinder.renderFile(this.tempPath, fileConfig))
.then(result => markbinder.renderFile(result, this.tempPath, fileConfig))
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we skip the intermediate output:

  • this.tempPath is no longer meaningful, and
  • this function should no longer be called renderFile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I've looked through the logic and removed Page#tempPath altogether.

Also, I've removed context as an argument for _parse in parser.js, since _parse just passes around context without doing anything to it.

@openorclose
Copy link
Contributor Author

Yes. I wonder how much it improves build time.

I tested it on the se-book website with

time for run in {1..10}; do npm run build; done

and got 45 minutes on the original and 41 minutes on this branch.

However, the variance was quite high when I ran the tests individually (all between 3:57-5:23 minutes), so don't think the build times improve by a lot.

});
const fileExt = utils.getExt(filePath);
if (utils.isMarkdownFileExt(fileExt)) {
const inputData = md.render(content);
Copy link
Contributor

Choose a reason for hiding this comment

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

One tiny nit:
inputData seems strange now that we are no longer reading from a file.
How about renderedContent?

Copy link
Contributor

@marvinchin marvinchin left a comment

Choose a reason for hiding this comment

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

LGTM

@marvinchin marvinchin added this to the v2.12.1 milestone Mar 23, 2020
@marvinchin marvinchin merged commit c437f3f into MarkBind:master Mar 23, 2020
Tejas2805 added a commit to Tejas2805/markbind that referenced this pull request Mar 23, 2020
* 'master' of https://github.com/MarkBind/markbind:
  Update test files (MarkBind#1138)
  Remove OK button from modals (MarkBind#1134)
  Add start from line number functionality to code blocks (MarkBind#1115)
  Allow special tags to be self-closing (MarkBind#1101)
  Simplify baseUrl resolving process (MarkBind#1087)
  Remove redundant file writing (MarkBind#1090)
  Bump acorn from 5.7.3 to 5.7.4 (MarkBind#1121)
  Bump acorn from 7.1.0 to 7.1.1 in /src/lib/markbind (MarkBind#1120)
  Unify markdown-it parser variants (MarkBind#1056)
  Remove dynamic include feature (MarkBind#1037)
  Fix flex shrink not applying in content wrapper (MarkBind#1135)
  Escape Nunjucks for special tags (MarkBind#1049)
  Update documentation on icon slot for boxes (MarkBind#1123)
Tejas2805 added a commit to Tejas2805/markbind that referenced this pull request Mar 23, 2020
…x-pageNav

* 'master' of https://github.com/MarkBind/markbind:
  Update test files (MarkBind#1138)
  Remove OK button from modals (MarkBind#1134)
  Add start from line number functionality to code blocks (MarkBind#1115)
  Allow special tags to be self-closing (MarkBind#1101)
  Simplify baseUrl resolving process (MarkBind#1087)
  Remove redundant file writing (MarkBind#1090)
  Bump acorn from 5.7.3 to 5.7.4 (MarkBind#1121)
  Bump acorn from 7.1.0 to 7.1.1 in /src/lib/markbind (MarkBind#1120)
  Unify markdown-it parser variants (MarkBind#1056)
  Remove dynamic include feature (MarkBind#1037)
  Fix flex shrink not applying in content wrapper (MarkBind#1135)
  Escape Nunjucks for special tags (MarkBind#1049)
  Update documentation on icon slot for boxes (MarkBind#1123)
  Convert code in boxes to code block (MarkBind#1086)
marvinchin pushed a commit that referenced this pull request Apr 10, 2020
We are writing to a temp path, and then reading it immediately.
Let's avoid this by passing the string directly instead.
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.

4 participants