Skip to content

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
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.

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

4 participants