# Rocq Sharing Analyser (new plugin to print debug info)

**URL:** <https://discourse.rocq-prover.org/t/rocq-sharing-analyser-new-plugin-to-print-debug-info/2463>\
**Category:** Announcements\
**Created:** [November 5, 2024, 2:07pm UTC](https://discourse.rocq-prover.org/t/rocq-sharing-analyser-new-plugin-to-print-debug-info/2463 "2024-11-05T14:07:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SkySkimmer](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/skyskimmer/32/369_2.png) [@SkySkimmer](https://discourse.rocq-prover.org/u/SkySkimmer)\
**Post date:** [November 5, 2024, 2:07pm UTC](https://discourse.rocq-prover.org/t/rocq-sharing-analyser-new-plugin-to-print-debug-info/2463/1 "2024-11-05T14:07:42Z")

</div>

> **[GitHub - SkySkimmer/rocq-sharing-analyser: Memory sharing analyser for Rocq (Coq)](https://github.com/SkySkimmer/rocq-sharing-analyser)**
>
> Memory sharing analyser for Rocq (Coq)

A term like `nat -> nat` can be expressed as 2 different graphs in memory:

```auto
  (->)
  / \
nat nat

```

and

```auto
  (->)
  / \
  \ /
   nat

```

In the second graph the occurrences of `nat` are shared, so it takes less memory.

When the terms get deeper the size of the graph with maximal sharing  
can be logarithmic in the size of the term seen as a tree (the tree has no sharing).  
For instance `(nat -> nat) -> (nat -> nat)` can be shared as

```auto
  (->)
  / \
  \ /
  (->)
  / \
  \ /
   nat

```

taking 3 nodes instead of 7.

This project provides a plugin to print debug information about how  
Rocq’s terms are structured in memory.

(Note: currently Rocq only uses in-memory sharing to reduce memory usage and  
shortcut some equality tests.)

See the [README](https://github.com/SkySkimmer/rocq-sharing-analyser/blob/master/README.md) and [Demo.v](https://github.com/SkySkimmer/rocq-sharing-analyser/blob/master/Demo.v) for details and examples.
