Skip to content

Conversation

nsajko
Copy link
Member

@nsajko nsajko commented Oct 10, 2024

Another follow-up to #51362.

Make sure the global default precision and rounding mode are only dereferenced when necessary (when there's no relevant scope, in the ScopedValues sense).

Currently this change doesn't result in performance improvements, presumably due to how costly the access to a ScopedValue currently is, but the idea is to avoid the cost of the dereference when possible.

Once ScopedValues are better optimized by the compiler, I guess this would also result in better effects in case it's known that a call is within a ScopedValues scope.

@nsajko nsajko added the bignums BigInt and BigFloat label Oct 10, 2024
nsajko added a commit to nsajko/julia that referenced this pull request Oct 10, 2024
Fixes several issues:
* Set `BigFloat` precision without mutating the global default, relying
  on the new ScopedValues functionality.
* Avoid reading the global defaults for the precision and rounding
  mode, relies on JuliaLang#56095.
* Try to ensure the loop terminates in a reasonable amount of time, and
  without trying to allocate excessively large `BigFloat` values.
nsajko added a commit to nsajko/julia that referenced this pull request Nov 6, 2024
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.
nsajko added a commit to nsajko/julia that referenced this pull request Nov 23, 2024
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.
nsajko added a commit to nsajko/julia that referenced this pull request Dec 3, 2024
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.
nsajko added a commit to nsajko/julia that referenced this pull request Dec 22, 2024
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.
Another follow-up to JuliaLang#51362.

Make sure the global default precision and rounding mode are only
dereferenced when necessary (when there's no relevant scope, in the
ScopedValues sense).

Currently this change doesn't result in performance improvements,
presumably due to how costly the access to a `ScopedValue` currently
is, but the idea is to avoid the cost of the dereference when
possible.

Once ScopedValues are better optimized by the compiler, I guess this
would also result in better effects in case it's known that a call is
within a ScopedValues scope.
@nsajko nsajko force-pushed the mpfr_avoid_dereferencing_globals branch from 6075ac5 to 9117f64 Compare January 16, 2025 00:31
nsajko added a commit to nsajko/julia that referenced this pull request Jan 16, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.
nsajko added a commit to nsajko/julia that referenced this pull request Jan 16, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.
nsajko added a commit to nsajko/julia that referenced this pull request Jan 23, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Jan 23, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Jan 23, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Jan 24, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Jan 26, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Jan 29, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Jan 30, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Feb 1, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Feb 2, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Feb 4, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Feb 10, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Feb 18, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Feb 19, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
nsajko added a commit to nsajko/julia that referenced this pull request Feb 24, 2025
Relying on `ScopedValues`, set `BigFloat` precision without mutating
the global default, while constructing `Rational` from
`AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with JuliaLang#56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
  relevant methods have `@assume_effects :foldable` applied, which
  includes `:effect_free`, which requires that no globals be mutated
  (followup on JuliaLang#55886)
* in the case of `AbstractIrrational` values in general, this PR
  prevents data races on the global `BigFloat` precision
fingolfin pushed a commit that referenced this pull request Feb 25, 2025
…ional` (#55853)

Relying on `ScopedValues`, set `BigFloat` precision without mutating the
global default, while constructing `Rational` from `AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with #56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
relevant methods have `@assume_effects :foldable` applied, which
includes `:effect_free`, which requires that no globals be mutated
(followup on #55886)
* in the case of `AbstractIrrational` values in general, this PR
prevents data races on the global `BigFloat` precision
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds plausible to me.

@fingolfin fingolfin merged commit deba118 into JuliaLang:master Feb 25, 2025
5 of 7 checks passed
@nsajko nsajko deleted the mpfr_avoid_dereferencing_globals branch February 25, 2025 10:24
KristofferC pushed a commit that referenced this pull request Feb 26, 2025
…ional` (#55853)

Relying on `ScopedValues`, set `BigFloat` precision without mutating the
global default, while constructing `Rational` from `AbstractIrrational`.

Also helps avoid reading the global defaults for the precision and
rounding mode, together with #56095.

What does this fix:
* in the case of the `Irrational` constants defined in `MathConstants`:
relevant methods have `@assume_effects :foldable` applied, which
includes `:effect_free`, which requires that no globals be mutated
(followup on #55886)
* in the case of `AbstractIrrational` values in general, this PR
prevents data races on the global `BigFloat` precision

(cherry picked from commit 2a89f71)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bignums BigInt and BigFloat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants