ng icon indicating copy to clipboard operation
ng copied to clipboard

Import regexp is slow

Open cflewis opened this issue 7 years ago • 1 comments

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 avatar Jan 08 '18 01:01 cflewis

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.

sbinet avatar Jan 08 '18 10:01 sbinet