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

Import regexp is slow #195

Open
cflewis opened this issue Jan 8, 2018 · 1 comment
Open

Import regexp is slow #195

cflewis opened this issue Jan 8, 2018 · 1 comment

Comments

@cflewis
Copy link

cflewis commented Jan 8, 2018

When I run

ng> import "regexp"

It takes a decent 3 to 4 seconds.

When I run

ng> import "strings"

it's as good as instant.

Even simple programs get hurt by this: If I wanted to write something that gets the path to a known parent directory (google3), I'd need to write:

#! /usr/bin/env ng

import "regexp"

pwd := $$ echo $PWD $$
import "regexp"
r := regexp.MustCompile("^.*google3")
s := r.FindString(pwd)
$$ echo $s $$

Is it simply because regexp has more imports than strings, or does strings have some special handling? Could regexp get that handling too?

P.S. why does fmt.Println(s) return

/foo/bar/google3
int(46)

?

@cflewis cflewis changed the title Import regexp is really slow Import regexp is slow Jan 8, 2018
@sbinet
Copy link
Collaborator

sbinet commented Jan 8, 2018

Hi Chris,
I don't have any insights as to why importing 'regexp' is so much slower than other packages.
I do suspect the same issue than you do though.

I can answer one thing though: 'fmt.Printf' returns the number of bytes written and an error.
As the error is 'nil', it's elided from the printout.
You do get the number of bytes though.
Then you get the message being printed out.

Note there are built-in 'print' and 'printf' functions in ng that don't return '(int, error)'. You'd probably want to use those instead in scripts.

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

No branches or pull requests

2 participants