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

Improve event processing performance #153

Merged
merged 4 commits into from
Dec 21, 2022
Merged

Improve event processing performance #153

merged 4 commits into from
Dec 21, 2022

Conversation

picklelo
Copy link
Contributor

  • Reorder if statements in format_state to handle most common vars first (this provided a big speedup)
  • Use super().__getattribute__ in functions in the critical path of event processing. It's ugly but it's faster.
  • Add onopen for web socket to hydrate the page on initial load.

@picklelo picklelo linked an issue Dec 21, 2022 that may be closed by this pull request
@picklelo
Copy link
Contributor Author

Test code:

# Perf testing...
import asyncio

from pynetree.pynetree import app
from pynecone.event import Event
from pynecone.app import process
token = '0'

async def do_loop():
    event = Event(token=token, name="counter_example_state.increment")
    update = await process(app, event)
    print(update)

async def main():
    for i in range(10000):
        print("loop", i)
        await do_loop()
    
asyncio.run(main())

Before:
Screen Shot 2022-12-20 at 4 08 02 PM

After:
Screen Shot 2022-12-20 at 10 01 12 PM

@FHU-yezi
Copy link
Contributor

Remove the print line in performance benchmark, it will slow this code down.

@picklelo
Copy link
Contributor Author

Remove the print line in performance benchmark, it will slow this code down.

It does slow the runtime, but I'm only visualizing inside the process function so the results should still be valid.

@picklelo picklelo requested a review from Alek99 December 21, 2022 20:28
@@ -123,8 +123,16 @@ export const updateState = async (state, result, setResult, router, socket) => {
* @param setResult The function to set the result.
* @param endpoint The endpoint to connect to.
*/
export const connect = async (socket, state, setResult, endpoint) => {
export const connect = async (socket, state, result, setResult, router, endpoint) => {
// Create the socket.
socket.current = new WebSocket(endpoint);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we eventually change this so its on socket per app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure tbh, we will need to investigate this.

@@ -851,8 +851,16 @@ def format_state(value: Any) -> Dict:
Raises:
TypeError: If the given value is not a valid state.
"""
# Handle dicts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice the reordering speed up

@picklelo picklelo merged commit 57e278a into main Dec 21, 2022
@picklelo picklelo deleted the nikhil/performance branch December 21, 2022 23:18
ACucos1 pushed a commit to ACucos1/rd-pynecone that referenced this pull request Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add profiling
3 participants