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

Transpilation Optimization #115

Merged
merged 16 commits into from
Nov 9, 2024

Conversation

HaidarJbeily7
Copy link
Contributor

@HaidarJbeily7 HaidarJbeily7 commented Nov 3, 2024

Overview:

Added utility function to skip unnecessary transpilation when source files haven't been modified. This optimization compares file modification timestamps to determine if retranspilation is needed, improving build performance.

Changes:

  • Added unit tests to verify skip/retranspile behavior
  • Implemented timestamp comparison logic
  • Handled case when transpiled file doesn't exist

PR-Codex overview

This PR refactors the transpilation process by introducing a prepare function, modifying the transpile function to use it, and adding a needsRetranspile check to optimize file processing. It also enhances test cases for retranspilation based on file modifications.

Detailed summary

  • Renamed transpile function to prepare.
  • Added a new transpile function that calls prepare.
  • Introduced retranspile function to handle cases when files are modified.
  • Implemented needsRetranspile function to check modification times.
  • Updated transform function to use needsRetranspile.
  • Enhanced test cases for verifying retranspilation behavior.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

eo2js/src/commands/transpile.js Outdated Show resolved Hide resolved
eo2js/src/commands/transpile.js Outdated Show resolved Hide resolved
eo2js/src/commands/transpile.js Outdated Show resolved Hide resolved
eo2js/src/commands/transpile.js Outdated Show resolved Hide resolved
eo2js/src/commands/transpile.js Outdated Show resolved Hide resolved
eo2js/src/commands/transpile.js Outdated Show resolved Hide resolved
eo2js/test/commands/transpile.test.js Outdated Show resolved Hide resolved
@HaidarJbeily7
Copy link
Contributor Author

@maxonfjvipon I have made the requested changes.

@HaidarJbeily7
Copy link
Contributor Author

Closes: #37

@@ -65,9 +73,28 @@ describe('transpile', function() {
});
['simple-test', 'alone-test'].forEach((name) => {
it(`should generate test JS file for ${name}`, function() {
assertFilesExist(transpile(name), target, [`project/com/eo2js/${name}.test.js`])
prepare(name)
Copy link
Member

Choose a reason for hiding this comment

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

@HaidarJbeily7 it became a little bit messy because prepare is called twice in beforeEach and in the test. I think the design of the helper functions here should be changed somehow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxonfjvipon I enhanced the helper functions a little bit. Please check again!

*/
const transpile = function(name = 'simple') {
prepare(name)
return runSync([
Copy link
Member

Choose a reason for hiding this comment

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

@HaidarJbeily7 I think you can call retranspile here to reduce code duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think calling retranspile in transpile may result in a code smell because of two reasons:

  • As an abstraction, re-something should call something not vice-versa
  • What if we need to add more logic regarding retranspilation here in the future? This would cause a problem as those two functions are tightly coupled.

Because of the above, I decided to duplicate the code. What do you think?

One solution I thought of to avoid code duplication:

  • Removeretranspile and Modify the transpile function to accept the prepare boolean flag here. So, when we re-transpile we don't resume to the initial state (copying files on Windows gives a carbon copy of the source file. I mean the same mtime -> resulting test failing)

@maxonfjvipon

const transpiled = path.resolve(target, '8-transpile/com/eo2js/simple.xmir')
const source = path.resolve(target, '6-verify/com/eo2js/simple.xmir')
const first = fs.statSync(transpiled).mtime
await new Promise((resolve) => setTimeout(resolve, 1000))
Copy link
Member

Choose a reason for hiding this comment

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

@HaidarJbeily7 why do we need timeout here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxonfjvipon Testing on windows might fail without deterministic waiting time here as for a case when a file is updated in a small timespan, it may result test failing here. (first and second mtime are equal)

https://blog.andreiavram.ro/time-precision-linux-windows/

@maxonfjvipon
Copy link
Member

@rultor merge

@rultor
Copy link
Collaborator

rultor commented Nov 9, 2024

@rultor merge

@maxonfjvipon OK, I'll try to merge now. You can check the progress of the merge here.

@rultor rultor merged commit fd125a4 into objectionary:master Nov 9, 2024
5 checks passed
@rultor
Copy link
Collaborator

rultor commented Nov 9, 2024

@rultor merge

@maxonfjvipon Done! FYI, the full log is here (took me 20min).

@maxonfjvipon
Copy link
Member

@HaidarJbeily7 Thanks

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