Giter VIP home page Giter VIP logo

strs's Issues

Optimize launch time

Problem

Here's the issue:

$ time python -c "import sys, emoji, fire, more_itertools"
real    0m0.121s
user    0m0.105s
sys     0m0.019s

$ time python -c "import fire"
real    0m0.106s
user    0m0.086s
sys     0m0.023s

$ time python -m strs isalnum 1
real    0m0.146s
user    0m0.115s
sys     0m0.033s

Start up time, at minimum, will have a ~100ms duration on a NVMe drive with hot caches.

This doesn't really matter when using strs on the command line, but when you're writing scripts with a lot of string manipulation, it can be relatively slow:

$ time echo "$(str repeat 5 test | str join : | str split : | str nth 1 2 3 | str join ' ' | str col 1)"
test
real    0m0.234s
user    0m0.861s
sys     0m0.168s

Potential solutions

Using click can shave off ~34ms from start up:

$ time python3 -c "import click"
real    0m0.072s
user    0m0.059s
sys     0m0.016s

Nuitka, in general, can give a 4x execution speed up, which can result in a ~28ms to ~37ms start up time. Mypyc and Nuitka don't support Python 3.10, but Numba does and so does Cython. I have to look further into PyOxidizer and PyO3.

It would also help to profile it and see exactly what's going on during start up. I think the script might just be hitting the disk heavily with imports that are spread across many files. Dynamically loading dependencies might help in that case, or inlining.

Or, instead of relying on pipes to pass strings through different manipulation commands, strs can use Fire's command chaining feature, or click's command chaining feature. The CLI API might have to change, and the input handling might need to be refactored, in order for command chaining to work nicely with the current code and how it's structured.

That, or I can just port it to Rust.

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.