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

rustdoc-search: reuse individual types in function signatures #119756

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

notriddle
Copy link
Contributor

Because search.js never mutates the function signature after loading it,
they can be safely and easily reused across functions.

This change doesn't change the format of the search index.
It only changes search.js.

Profiler output: https://notriddle.com/rustdoc-html-demo-9/fn-signature-opti2/index.html

benchmarkbeforeafter
arti
user: 002.228 s
sys:  000.315 s
wall: 001.663 s
child_RSS_high:     315668 KiB
group_mem_high:     285948 KiB
user: 001.805 s
sys:  000.231 s
wall: 001.398 s
child_RSS_high:     235864 KiB
group_mem_high:     203056 KiB
cortex-m
user: 000.143 s
sys:  000.035 s
wall: 000.140 s
child_RSS_high:      59168 KiB
group_mem_high:      23000 KiB
user: 000.138 s
sys:  000.031 s
wall: 000.133 s
child_RSS_high:      58944 KiB
group_mem_high:      22220 KiB
sqlx
user: 000.792 s
sys:  000.115 s
wall: 000.536 s
child_RSS_high:     156716 KiB
group_mem_high:     122948 KiB
user: 000.824 s
sys:  000.084 s
wall: 000.535 s
child_RSS_high:     136668 KiB
group_mem_high:     101792 KiB
stm32f4
user: 006.665 s
sys:  003.533 s
wall: 008.624 s
child_RSS_high:    1037660 KiB
group_mem_high:    1022516 KiB
user: 005.997 s
sys:  003.185 s
wall: 007.987 s
child_RSS_high:     832068 KiB
group_mem_high:     810908 KiB
stm32f4xx-hal
user: 000.317 s
sys:  000.051 s
wall: 000.203 s
child_RSS_high:      77060 KiB
group_mem_high:      41776 KiB
user: 000.287 s
sys:  000.046 s
wall: 000.180 s
child_RSS_high:      75216 KiB
group_mem_high:      39200 KiB
ripgrep
user: 000.463 s
sys:  000.063 s
wall: 000.295 s
child_RSS_high:     101288 KiB
group_mem_high:      66364 KiB
user: 000.472 s
sys:  000.036 s
wall: 000.247 s
child_RSS_high:      82708 KiB
group_mem_high:      47056 KiB

Map is implemented as a pointer to a mutable object.
Rustdoc never mutates function signatures after constructing them,
but the JS engine doesn't know that.

To save a bunch of memory, use a single immutable map
for every decoded type object with no bindings or generics.
@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2024

r? @jsha

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 9, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2024

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha

This takes advantage of more reuse opportunities.
Along with the empty object commit, they
bringing memory usage down about 20% over the original.
@GuillaumeGomez
Copy link
Member

Great work, thanks!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 9, 2024

📌 Commit c3cd657 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 9, 2024
…uillaumeGomez

rustdoc-search: reuse individual types in function signatures

Because `search.js` never mutates the function signature after loading it,
they can be safely and easily reused across functions.

This change doesn't change the format of the search index.
It only changes `search.js`.

Profiler output: https://notriddle.com/rustdoc-html-demo-9/fn-signature-opti2/index.html

<table><tr><th>benchmark<th>before<th>after

<tr><th>arti<td>

```
user: 002.228 s
sys:  000.315 s
wall: 001.663 s
child_RSS_high:     315668 KiB
group_mem_high:     285948 KiB
```

<td>

```
user: 001.805 s
sys:  000.231 s
wall: 001.398 s
child_RSS_high:     235864 KiB
group_mem_high:     203056 KiB
```

<tr><th>cortex-m<td>

```
user: 000.143 s
sys:  000.035 s
wall: 000.140 s
child_RSS_high:      59168 KiB
group_mem_high:      23000 KiB
```

<td>

```
user: 000.138 s
sys:  000.031 s
wall: 000.133 s
child_RSS_high:      58944 KiB
group_mem_high:      22220 KiB
```

<tr><th>sqlx<td>

```
user: 000.792 s
sys:  000.115 s
wall: 000.536 s
child_RSS_high:     156716 KiB
group_mem_high:     122948 KiB
```

<td>

```
user: 000.824 s
sys:  000.084 s
wall: 000.535 s
child_RSS_high:     136668 KiB
group_mem_high:     101792 KiB
```

<tr><th>stm32f4<td>

```
user: 006.665 s
sys:  003.533 s
wall: 008.624 s
child_RSS_high:    1037660 KiB
group_mem_high:    1022516 KiB
```

<td>

```
user: 005.997 s
sys:  003.185 s
wall: 007.987 s
child_RSS_high:     832068 KiB
group_mem_high:     810908 KiB
```

<tr><th>stm32f4xx-hal<td>

```
user: 000.317 s
sys:  000.051 s
wall: 000.203 s
child_RSS_high:      77060 KiB
group_mem_high:      41776 KiB
```

<td>

```
user: 000.287 s
sys:  000.046 s
wall: 000.180 s
child_RSS_high:      75216 KiB
group_mem_high:      39200 KiB
```

<tr><th>ripgrep<td>

```
user: 000.463 s
sys:  000.063 s
wall: 000.295 s
child_RSS_high:     101288 KiB
group_mem_high:      66364 KiB
```

<td>

```
user: 000.472 s
sys:  000.036 s
wall: 000.247 s
child_RSS_high:      82708 KiB
group_mem_high:      47056 KiB
```

</tr></table>
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2024
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#117372 (Update stdarch submodule)
 - rust-lang#118241 (Making `User<T>` and `User<[T]>` `Send`)
 - rust-lang#118748 (std: getrandom simplification for freebsd.)
 - rust-lang#119527 (don't reexport atomic::ordering via rustc_data_structures, use std import)
 - rust-lang#119699 (Merge dead bb pruning and unreachable bb deduplication.)
 - rust-lang#119723 (Remove `-Zdont-buffer-diagnostics`.)
 - rust-lang#119756 (rustdoc-search: reuse individual types in function signatures)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2024
…llaumeGomez

Rollup of 9 pull requests

Successful merges:

 - rust-lang#117556 (Disallow reference to `static mut` and adding `static_mut_ref` lint)
 - rust-lang#118748 (std: getrandom simplification for freebsd.)
 - rust-lang#119282 (Rework and improve the unstable documentation of check-cfg)
 - rust-lang#119527 (don't reexport atomic::ordering via rustc_data_structures, use std import)
 - rust-lang#119668 (Simplify implementation of MIR promotion)
 - rust-lang#119699 (Merge dead bb pruning and unreachable bb deduplication.)
 - rust-lang#119723 (Remove `-Zdont-buffer-diagnostics`.)
 - rust-lang#119756 (rustdoc-search: reuse individual types in function signatures)
 - rust-lang#119758 (GNU/Hurd: unconditionally use inline stack probes)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2024
…llaumeGomez

Rollup of 9 pull requests

Successful merges:

 - rust-lang#117556 (Disallow reference to `static mut` and adding `static_mut_ref` lint)
 - rust-lang#118748 (std: getrandom simplification for freebsd.)
 - rust-lang#119282 (Rework and improve the unstable documentation of check-cfg)
 - rust-lang#119527 (don't reexport atomic::ordering via rustc_data_structures, use std import)
 - rust-lang#119668 (Simplify implementation of MIR promotion)
 - rust-lang#119699 (Merge dead bb pruning and unreachable bb deduplication.)
 - rust-lang#119723 (Remove `-Zdont-buffer-diagnostics`.)
 - rust-lang#119756 (rustdoc-search: reuse individual types in function signatures)
 - rust-lang#119758 (GNU/Hurd: unconditionally use inline stack probes)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f9cadb9 into rust-lang:master Jan 9, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 9, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2024
Rollup merge of rust-lang#119756 - notriddle:notriddle/reuse-map, r=GuillaumeGomez

rustdoc-search: reuse individual types in function signatures

Because `search.js` never mutates the function signature after loading it,
they can be safely and easily reused across functions.

This change doesn't change the format of the search index.
It only changes `search.js`.

Profiler output: https://notriddle.com/rustdoc-html-demo-9/fn-signature-opti2/index.html

<table><tr><th>benchmark<th>before<th>after

<tr><th>arti<td>

```
user: 002.228 s
sys:  000.315 s
wall: 001.663 s
child_RSS_high:     315668 KiB
group_mem_high:     285948 KiB
```

<td>

```
user: 001.805 s
sys:  000.231 s
wall: 001.398 s
child_RSS_high:     235864 KiB
group_mem_high:     203056 KiB
```

<tr><th>cortex-m<td>

```
user: 000.143 s
sys:  000.035 s
wall: 000.140 s
child_RSS_high:      59168 KiB
group_mem_high:      23000 KiB
```

<td>

```
user: 000.138 s
sys:  000.031 s
wall: 000.133 s
child_RSS_high:      58944 KiB
group_mem_high:      22220 KiB
```

<tr><th>sqlx<td>

```
user: 000.792 s
sys:  000.115 s
wall: 000.536 s
child_RSS_high:     156716 KiB
group_mem_high:     122948 KiB
```

<td>

```
user: 000.824 s
sys:  000.084 s
wall: 000.535 s
child_RSS_high:     136668 KiB
group_mem_high:     101792 KiB
```

<tr><th>stm32f4<td>

```
user: 006.665 s
sys:  003.533 s
wall: 008.624 s
child_RSS_high:    1037660 KiB
group_mem_high:    1022516 KiB
```

<td>

```
user: 005.997 s
sys:  003.185 s
wall: 007.987 s
child_RSS_high:     832068 KiB
group_mem_high:     810908 KiB
```

<tr><th>stm32f4xx-hal<td>

```
user: 000.317 s
sys:  000.051 s
wall: 000.203 s
child_RSS_high:      77060 KiB
group_mem_high:      41776 KiB
```

<td>

```
user: 000.287 s
sys:  000.046 s
wall: 000.180 s
child_RSS_high:      75216 KiB
group_mem_high:      39200 KiB
```

<tr><th>ripgrep<td>

```
user: 000.463 s
sys:  000.063 s
wall: 000.295 s
child_RSS_high:     101288 KiB
group_mem_high:      66364 KiB
```

<td>

```
user: 000.472 s
sys:  000.036 s
wall: 000.247 s
child_RSS_high:      82708 KiB
group_mem_high:      47056 KiB
```

</tr></table>
@notriddle notriddle deleted the notriddle/reuse-map branch January 9, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants