fthomas / fthomas/refined

`Greater[5] Or Equal[5]` results in drastic performance problems with `unsafeFrom`

Open
#1,161 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
1.7k
Forks
152
Avg merge
1h 20m
Merged PRs (30d)
6

Description

Running the following takes more than a minute to complete for me:
```scala
type Crazy = Int Refined (Greater[5] Or Equal[5])
object Crazy extends RefinedTypeOps.Numeric[Crazy, Int]
val crazy = Crazy.unsafeFrom(5)
```
However, the following is fine:
```scala
val sane: Crazy = refineV[Greater[5] Or Equal[5]](5).toOption.get
```

Here is a scastie demonstrating the problem:
https://scastie.scala-lang.org/oGPpPS59RcG8ejX9dSDhhQ
It just gets `closed`, but when run locally it will eventually return.

I have tried refined versions `0.9.29` through `0.10.2` and scala versions `2.13.8` and `3.2.2`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the two Scala examples locally, using the versions reported in the issue, and compare `Crazy.unsafeFrom(5)` with `refineV[Greater[5] Or Equal[5]](5).toOption.get`. The Scastie link provides the minimal reproduction. Done means the `unsafeFrom` case no longer takes more than a minute while preserving the refined type behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.