Exponential slowdown in Streamlit as the number of widgets increases (starting in v1.34)
### Checklist

- [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.
- [X] I added a very descriptive title to this issue.
- [X] I have provided sufficient information below to help reproduce this issue.

### Summary

There is an exponential slowdown in Streamlit as the number of input widgets is increases. This started happening with the 1.34 release and is tied to PR #8529. Calling [`get_session_state()`](https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/elements/widgets/number_input.py#L390) in the widgets is triggering this [dict comp method](https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/runtime/state/session_state.py#L370) exponentially more times than previously. For a simple app containing 200 number inputs, there is a 50x increase in calls to `_reverse_key_wid_map` which causes the app to take over 1s to re-load locally (vs ~0.2s with release 1.33). Here is a plot of the number of calls vs the number of inputs:

![image](https://github.com/user-attachments/assets/4b0ef9c9-49c4-482b-85d9-9684e41f523d)

### Reproducible Code Example

```Python
import streamlit as st
import time
import random

NUM_TABS = 10
NUM_INPUTS = 20


def create_inputs(t):
    for i in range(NUM_INPUTS):
        key = f"tab_{t + 1}_input_{i + 1}_value"
        if key in st.session_state:
            value = st.session_state[key]
        else:
            value = random.randint(0, 100000)
        st.number_input(
            label=f"Number Input {i + 1}",
            value=value,
            min_value=0,
            step=1,
            format="%d",
            key=key,
        )


def main():
    st.title("My dummy app")
    with st.container(border=True, height=500):
        tabs = st.tabs([f"Tab {i + 1}" for i in range(NUM_TABS)])
        for t, tab in enumerate(tabs):
            with tab:
                create_inputs(t)


if __name__ == "__main__":
    import cProfile
    from pstats import Stats

    pr = cProfile.Profile()
    pr.enable()

    start_time = time.time()
    main()
    st.info(f"run time: {time.time() - start_time:.3f} seconds")

    pr.disable()
    stats = Stats(pr)
    stats.sort_stats("tottime").print_stats(10)
```

### Steps To Reproduce

1. Run the app using Streamlit version 1.33
2. Adjust `NUM_TABS` value from 1 to 10 and monitor the `cProfile` output
3. Switch to Streamlit version 1.34 or above
4. Repeat step 2

here is a screenshot of the cProfile output with Streamlit 1.33 using 200 widgets:
![image](https://github.com/user-attachments/assets/2c39e939-5cc9-407a-99f1-e1c9de0257b2)

and here's a screenshot using Streamlit 1.34:
![image](https://github.com/user-attachments/assets/3da40e2d-025c-4752-9a96-6b10b233a0bd)

### Expected Behavior

_No response_

### Current Behavior

_No response_

### Is this a regression?

- [x] Yes, this used to work in a previous version.

### Debug info

- Streamlit version: 1.33 vs 1.34+
- Python version: 3.11
- Operating System: Windows 10
- Browser: Chrome


### Additional Information

_No response_