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

Base.MPFR: avoid reading the global defaults unless necessary #56095

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nsajko
Copy link
Contributor

@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
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.

1 participant