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

Rewrite rules for toString/toText #212

Closed
Martoon-00 opened this issue May 30, 2019 · 0 comments · Fixed by #213
Closed

Rewrite rules for toString/toText #212

Martoon-00 opened this issue May 30, 2019 · 0 comments · Fixed by #213
Labels
type:feature Something new is added.

Comments

@Martoon-00
Copy link
Member

Problem: we consider using Text everywhere a good practice, but many libraries use String instead, and some function may perform toString just to scan/modify text contents. This may cause unnecessary toText followed by toString conversions.

Solution: add rewrite rules for this case.

Probably toString . (fromString :: String -> Text) case would be also interesting.

Martoon-00 added a commit that referenced this issue May 30, 2019
Closes #212.

I had to add `stringToText` and `textToString` functions in order to
specify inlining pragma as mentioned
[here](https://gitlab.haskell.org/ghc/ghc/issues/12632).

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 186.1 μs   (183.3 μs .. 188.4 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 189.4 μs   (187.7 μs .. 191.8 μs)
std dev              7.508 μs   (5.823 μs .. 10.36 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Martoon-00 added a commit that referenced this issue May 30, 2019
Closes #212.

I had to add `stringToText` and `textToString` functions in order to
specify inlining pragma as mentioned
[here](https://gitlab.haskell.org/ghc/ghc/issues/12632).

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 186.1 μs   (183.3 μs .. 188.4 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 189.4 μs   (187.7 μs .. 191.8 μs)
std dev              7.508 μs   (5.823 μs .. 10.36 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Martoon-00 added a commit that referenced this issue May 30, 2019
Closes #212.

I had to add `stringToText` and `textToString` functions in order to
specify inlining pragma as mentioned
[here](https://gitlab.haskell.org/ghc/ghc/issues/12632).

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 186.1 μs   (183.3 μs .. 188.4 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 189.4 μs   (187.7 μs .. 191.8 μs)
std dev              7.508 μs   (5.823 μs .. 10.36 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Martoon-00 added a commit that referenced this issue May 30, 2019
Closes #212.

I had to add `stringToText` and `textToString` functions in order to
specify inlining pragma as mentioned
[here](https://gitlab.haskell.org/ghc/ghc/issues/12632).

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 185.6 μs   (182.7 μs .. 188.2 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 187.0 μs   (185.2 μs .. 189.4 μs)
std dev              7.211 μs   (5.623 μs .. 10.07 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Martoon-00 added a commit that referenced this issue May 30, 2019
Closes #212.

I had to add `stringToText` and `textToString` functions in order to
specify inlining pragma as mentioned
[here](https://gitlab.haskell.org/ghc/ghc/issues/12632).

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 185.6 μs   (182.7 μs .. 188.2 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 187.0 μs   (185.2 μs .. 189.4 μs)
std dev              7.211 μs   (5.623 μs .. 10.07 μs)
variance introduced by outliers: 20% (moderately inflated)
```
@gromakovsky gromakovsky added the type:feature Something new is added. label Jun 3, 2019
@gromakovsky gromakovsky added this to the v1.6.0: it's alive milestone Jun 3, 2019
Martoon-00 added a commit that referenced this issue Jun 3, 2019
Added rewrite rule to eliminate toString . toText conversions.

Closes #212.

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 185.6 μs   (182.7 μs .. 188.2 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 187.0 μs   (185.2 μs .. 189.4 μs)
std dev              7.211 μs   (5.623 μs .. 10.07 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Martoon-00 added a commit that referenced this issue Jul 18, 2019
Added rewrite rule to eliminate toString . toText conversions.

Closes #212.

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 185.6 μs   (182.7 μs .. 188.2 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 187.0 μs   (185.2 μs .. 189.4 μs)
std dev              7.211 μs   (5.623 μs .. 10.07 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Martoon-00 added a commit that referenced this issue Jul 26, 2019
Added rewrite rule to eliminate toString . toText conversions.

Closes #212.

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 185.6 μs   (182.7 μs .. 188.2 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 187.0 μs   (185.2 μs .. 189.4 μs)
std dev              7.211 μs   (5.623 μs .. 10.07 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Martoon-00 added a commit that referenced this issue Jul 26, 2019
Added rewrite rule to eliminate toString . toText conversions.

Closes #212.

Benchmarks without rewrite rule:

```
benchmarked toText/toString
time                 1.013 ms   (875.1 μs .. 1.148 ms)
                     0.819 R²   (0.691 R² .. 0.904 R²)
mean                 1.621 ms   (1.268 ms .. 2.619 ms)
std dev              2.134 ms   (331.2 μs .. 4.071 ms)
variance introduced by outliers: 97% (severely inflated)
```

And with rewrite rule:

```
benchmarked toText/toString
time                 185.6 μs   (182.7 μs .. 188.2 μs)
                     0.998 R²   (0.996 R² .. 0.999 R²)
mean                 187.0 μs   (185.2 μs .. 189.4 μs)
std dev              7.211 μs   (5.623 μs .. 10.07 μs)
variance introduced by outliers: 20% (moderately inflated)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature Something new is added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants