Skip to content

Conversation

@filipeom
Copy link
Member

This commit fundamentally changes the representation of expressions (t) by lifting constant values out of the hash-consing machinery.

Changes:

  • t is now a variant: Imm of Value.t | Sym of expr Hc.hash_consed.
  • Removed Val and Loc constructors from the underlying expr type.
  • Constants are no longer hash-consed; they are stored directly as Imm.

Potential Performance Improvements:

  • Creating constant expressions no longer requires a hash-cons table lookup or allocation of a hash-cons node.
  • The global hash-cons table is no longer polluted with ephemeral constant values.

BREAKING CHANGE: Previously, because all expressions were hash-consed, structural equality implied physical equality (phys_equal was sufficient for all comparisons).

This invariant no longer holds for Imm values.

@filipeom filipeom requested a review from a team as a code owner January 19, 2026 23:46
@filipeom filipeom force-pushed the filipe/dont-hashcons-values branch from 0c52d6a to 09b4f0f Compare January 20, 2026 00:51
This commit fundamentally changes the representation of expressions (`t`)
by lifting constant values out of the hash-consing machinery.

Changes:

- `t` is now a variant: `Imm of Value.t | Sym of expr Hc.hash_consed`.
- Removed `Val` and `Loc` constructors from the underlying `expr` type.
- Constants are no longer hash-consed; they are stored directly as `Imm`.

Potential Performance Improvements:

- Creating constant expressions  no longer requires a hash-cons table lookup or allocation of a hash-cons node.
- The global hash-cons table is no longer polluted with ephemeral constant values.

BREAKING CHANGE: Previously, because all expressions were hash-consed, structural
equality implied physical equality (`phys_equal` was sufficient for all comparisons).

This invariant no longer holds for `Imm` values.
@filipeom filipeom force-pushed the filipe/dont-hashcons-values branch from 09b4f0f to 3d28c8d Compare January 20, 2026 08:12
@redianthus
Copy link
Contributor

redianthus commented Jan 22, 2026

What is the impact on performances for ECMA-SL on your hash-consing heavy program you mentioned? (The one where switching from weak to strong reduced the overhead from 40% to 20%)

@filipeom
Copy link
Member Author

What is the impact on performances for ECMA-SL on your hash-consing heavy program you mentioned? (The one where switching from weak to strong reduced the overhead from 40% to 20%)

It's around 14% with this PR. So the issue may actually be in ECMA-SL. I think we might be generating very hashconsing unfriendly expressions. I'm now trying to get tracing into ECMA-SL and smtml to see if I can identify what types of formualas/expressions cause the slowdown.

In owi I really didn't see any change between the three branches 😅

@redianthus
Copy link
Contributor

Interesting. Have you tried using landmarks while running this particular program?

@filipeom
Copy link
Member Author

Interesting. Have you tried using landmarks while running this particular program?

Not yet! But I was very interested in what you did in Owi (I think this was the PR OCamlPro/owi#871?). I think we will experiment doing the same thing in ECMA-SL. It should be easier since we're not multicore 😅

@filipeom filipeom marked this pull request as draft January 22, 2026 12:29
@redianthus
Copy link
Contributor

Yes, there is nothing you should do to get it working. Simply add:

 (instrumentation
  (backend landmarks --auto)))

to your library/executable in dune.

Then :

OCAML_LANDMARKS=on dune exec --instrument-with landmarks --profile release -- owi run test/run/binary_loop.wasm

@hra687261
Copy link
Contributor

Interesting. Have you tried using landmarks while running this particular program?

Not yet! But I was very interested in what you did in Owi (I think this was the PR OCamlPro/owi#871?). I think we will experiment doing the same thing in ECMA-SL. It should be easier since we're not multicore 😅

(This is the right PR: OCamlPro/owi#872 that one is outdated :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants