Code Monkey home page Code Monkey logo

Comments (5)

dsherret avatar dsherret commented on June 12, 2024 1

Actually, I'm going to consolidate the deno code to use the node code and in the meantime fix this perf issue.

from ts-morph.

maxpatiiuk avatar maxpatiiuk commented on June 12, 2024

Less critical, but out of 40s, 2s was spent in this function, thus if possible it should be optimized better too:

/**
* Gets the standardized absolute path.
* @param fileSystem - File system.
* @param fileOrDirPath - Path to standardize.
* @param relativeBase - Base path to be relative from.
*/
static getStandardizedAbsolutePath(fileSystem: FileSystemHost, fileOrDirPath: string, relativeBase?: string): StandardizedFilePath {
return FileUtils.standardizeSlashes(path.normalize(getAbsolutePath())) as StandardizedFilePath;
function getAbsolutePath() {
if (isAbsolutePath(fileOrDirPath))
return fileOrDirPath;
if (!fileOrDirPath.startsWith("./") && relativeBase != null)
return path.join(relativeBase, fileOrDirPath);
return path.join(fileSystem.getCurrentDirectory(), fileOrDirPath);
}
}

The fact that this function creates another function inside of it is a possible culprit

Screenshot 2023-12-01 at 09 11 04

from ts-morph.

maxpatiiuk avatar maxpatiiuk commented on June 12, 2024

For reference, this is how I captured and inspected the performance:

# I am running Node.js like this:
node --cpu-prof --cpu-prof-dir ~/Downloads/node --no-warnings=ExperimentalWarning --loader @swc-node/register/esm ./myScript.ts
# But if you are dealing with .js file, this would work too:
node --cpu-prof --cpu-prof-dir ~/Downloads/node ./myScript.js
# (The performance issue is independent of using a TypeScript loader)

That creates several .cpuprofile files in the ~/Downloads/node directory. Pick the largest among those, and open it in https://www.speedscope.app/. In that tool, use the "Sanditch" view, and sort by "Self" time to see functions which are good targets for further optimization.

from ts-morph.

dsherret avatar dsherret commented on June 12, 2024

@maxxxxxdlp thanks for benchmarking it! Feel free to submit a PR. I don't have time to spend on performance optimizations unfortunately (though I'll probably get to this eventually).

from ts-morph.

maxpatiiuk avatar maxpatiiuk commented on June 12, 2024

Can confirm the performance issue with statSync/captureLargerStackTrace is resolved in the most recent release. Thanks for the quick fix!

from ts-morph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.