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

[PATCH]Read synchronously for larger files while concatenating #128

Conversation

akashdsouza
Copy link
Contributor

First stab at #113. I'm not sure if this is the intended solution for the issue. I have started looking into broccoli plugins and this seemed like a good place to start.

};

if (this._isContentLarge(content)) {
entry.content = '';
entry.isFileContentLarge = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

an alternative may be:

entry.isInMemory = true | false

};

if (this._isContentLarge(content)) {
entry.content = '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets do null or undefined here, that way we can disambiguate between empty content and no content.

@@ -76,10 +92,16 @@ class SimpleConcat {
}

let entry = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

My early thoughts were something like:

class Entry {
  constructor(path) {
    this._content = undefined;
   this.path = path;
  }

  get  content() {
     if (this._content !== undefined) { return this._content; }
     let result = fs.readFileSync(this.path, 'UTF8');
     if (result.length < TRESHOLD) { this._content = content; }

     return result;
  }
}

Obviously I am open to other approaches. Just figured I would share.

Copy link
Contributor Author

@akashdsouza akashdsouza Jul 20, 2018

Choose a reason for hiding this comment

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

So, if I'm understanding this right, in this approach, we will not be updating the content in entry during add and update the first time. It would be computed just in result.

I think this might make the PR a lot simpler than what I have written and also get rid of the global baseDir(I really didn't want to do that).

Copy link
Contributor Author

@akashdsouza akashdsouza Jul 20, 2018

Choose a reason for hiding this comment

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

However, it seems like doing this might complicate writing unit tests as content need to be read from file instead of being assigned directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

However, it seems like doing this might complicate writing unit tests as content need to be read from file instead of being assigned directly

Slightly more yes, but using node-fixturify should nearly mitigate this issue. (I think)

@@ -1,8 +1,13 @@
'use strict';

const findIndex = require('find-index');
const fs = require('fs');
let baseDir;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will need to be addressed before we can land

@akashdsouza akashdsouza force-pushed the patch_retain_mitigate_memory_overhead branch from 5e48539 to 26f02e7 Compare July 23, 2018 07:37
@akashdsouza
Copy link
Contributor Author

I have made changes as per the other approach. This does look cleaner. But, I'm not sure about the changes I have made to the unit tests.

If these changes look good, I can squash the commits together

'a.js': fileContent
};
writeFixturifySync(obj);
concat.addFile(`${testDir}/a.js`, fileContent);
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of ${testDir} in all this addFiles could we specify baseDir when creating SimpleConcat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. I feel stupid for not doing something so obvious

@stefanpenner
Copy link
Collaborator

If these changes look good, I can squash the commits together

these look good, i did leave 1 comment though

@stefanpenner
Copy link
Collaborator

Reading this made me realize I think there is some code cleanup -> #129 thoughts?

@akashdsouza akashdsouza force-pushed the patch_retain_mitigate_memory_overhead branch from 26f02e7 to ec6877c Compare July 25, 2018 12:29
@akashdsouza
Copy link
Contributor Author

Reading this made me realize I think there is some code cleanup -> #129 thoughts?

It does look like it can be removed. I did a quick github search and there doesn't seem to be any weird usage.

@stefanpenner stefanpenner merged commit 77d038a into broccolijs:master Jul 25, 2018
@stefanpenner
Copy link
Collaborator

released as v3.5.0 🎉

@stefanpenner
Copy link
Collaborator

I think this may be causing: #130

@stefanpenner
Copy link
Collaborator

reverting this fixes #130 I'm going to roll this back.
@akashdsouza mind investigating?

@akashdsouza
Copy link
Contributor Author

This PR depends on inputNode being a directory path. From what I have checked so far based on #131, the issue is caused when inputNode is a node returned from another broccoli-plugin.

@akashdsouza
Copy link
Contributor Author

Although I haven't tested this yet, I think we can get around this by using this.inputNode.outputPath when inputNode is not a string. I will try doing this.

@akashdsouza
Copy link
Contributor Author

I think we can get around this by using this.inputNode.outputPath when inputNode is not a string

This seems to work. However, I don't know enough about the internals of broccoli's node handling to confirm that this is the right approach. @stefanpenner Thoughts?

@rwjblue
Copy link
Member

rwjblue commented Jul 26, 2018

In general you cannot make any assumptions about what this.inputNode will be, you can only operate on the directories in this.inputPaths...

@akashdsouza
Copy link
Contributor Author

Does this mean that I can use this.inputPaths[0] to get the directory as used in the _doLegacyBuild method?

@rwjblue
Copy link
Member

rwjblue commented Jul 27, 2018

Yes

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.

3 participants