Skip to content

Need more builtins #152

Closed
Closed

Description

@lilyball

Fish really needs more builtins. The two that I'm interested in right now are printf and seq. I have a function in bash that prints out the full 256-color table, using for (( g = 0; g < 6; g++ )) syntax for looping and printf for actually printing each color. time reports this function as taking 0.01 seconds.

The equivalent in Fish requires using seq for loop iteration and either using printf for convenience or using echo for a more awkward command-line that's built in. I'm actually not sure how to even time this since time itself isn't a builtin (but in bash it is). If I time the invocation fish -c rainbow256 (using printf), it takes 1.44s. time fish -c 'echo hi' takes only 0.17s so the rainbow256 function probably takes 1.27s. This is a far cry from the 0.01s that bash took. Modifying the function to use echo instead of printf takes 1.12s overall (0.95s adjusted). And removing the seq (by hardcoding its return value) drops this down to 1.02s (0.85s adjusted).

Overall, the lack of these two builtins (seq and printf) accounted for 0.42s running time, which is almost 30% of the overall time. I imagine most of the remaining time is due to the last non-builtin I'm using, which is math. Bash has builtin math functionality via ((, but Fish relies on a wrapper for bc.

My original bash script is https://gist.github.com/2951771.

My "optimized" fish script is https://gist.github.com/2951774

Activity

  1. ridiculousfish commented on Jul 9, 2012

    @ridiculousfish
    Member

    seq is annoying because it has different behavior on BSD and OS X than it does on Linux (in particular the behavior of seq 0)

  2. JeanMertz commented on Nov 25, 2012

    @JeanMertz
    Contributor

    I would like add my vote for a builtin printf. In Bash (an Zsh) I used it extensively for all my pretty-prompt printing needs. After switching to Fish a few days ago, I noticed my prompt becoming somewhat slow, even after converting all my bash/sh scripts to pure fish scripts.

    Turns out, I should ease up on the printf and use echo instead. A pity, because I much prefer the printf syntax.

  3. siteshwar commented on Nov 25, 2012

    @siteshwar
    Contributor

    Design philosophy of fish is to add builtins only when they can't be avoided (See Examples in "The law of minimalism" section here : http://ridiculousfish.com/shell/user_doc/html/design.html ). Still we made echo a builtin to make prompts faster, I am not sure we should do same for printf.

  4. JeanMertz commented on Nov 25, 2012

    @JeanMertz
    Contributor

    I am aware of this philosophy, and I fully agree with it. However, I also believe there is a fine line between "Lean and mean" and "Simple and slow".

    Fish is by no means simple, and as you pointed out, all the tools are still available as external commands. However, I do believe it should be possible to debate which builtin tools would improve performance for the majority of users without incurring any other overhead/penalties.

    For me, printf (and to lesser extend seq and math) would be a nice addition as builtin commands, but I also understand the reasons for not having it builtin (yet).

  5. ridiculousfish commented on Nov 25, 2012

    @ridiculousfish
    Member

    printf is a complicated beast. If someone were to provide it as a patch or pull request, I'd take it, as long as it came with a good test suite.

    If anyone decides to tackle this, IEEE Std 1003.1 will be your friend.

  6. siteshwar commented on Mar 22, 2013

    @siteshwar
    Contributor

    @JeanMertz printf has been added as builtin in fish with 3830c0a

  7. lilyball commented on Oct 29, 2014

    @lilyball
    ContributorAuthor

    This ticket is a bit abstract. We already have printf so at this point the only concrete suggestion is a builtin for seq, although since seq behaves differently in BSD vs GNU, adding a builtin for it is not necessarily correct (because the builtin would deviate from platform behavior on at least one platform).

    I'm going to close this out in favor of filing more targeted tickets on specific desired builtins.

  8. modified the milestones: fish 2.2.0, fish-future on Feb 8, 2016
  9. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions