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

We can speed up switch object #3058

Open
maxonfjvipon opened this issue Apr 6, 2024 · 3 comments · Fixed by #3103
Open

We can speed up switch object #3058

maxonfjvipon opened this issue Apr 6, 2024 · 3 comments · Fixed by #3103

Comments

@maxonfjvipon
Copy link
Member

Current implementation of switch object uses tuple.at object which is convenient for retrieval object by index but quite heavy.
Instead we can implement some recursive algorithm that can just do cases.head and cases.tail instead. Something similar to #3048 but in EO

Copy link

github-actions bot commented Apr 6, 2024

@maxonfjvipon thanks for the report, but here some unclear moments:

  • The title of the bug report is not descriptive enough. It should briefly summarize the problem instead of suggesting a solution. For example, it could be "Performance issue with switch object due to use of tuple.at object".
  • The bug report lacks crucial information such as the impact of the issue, the steps to reproduce it, and the expected versus actual results. These details are important for understanding the severity and scope of the bug.
  • The bug report seems to suggest a solution ("Instead we can implement some recursive algorithm..."). This is not the purpose of a bug report. Instead, it should focus on describing the problem in as much detail as possible. The solution should be discussed separately.

Please fix the bug report in order it to get resolved faster.
Analyzed with gpt-4

levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 17, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 17, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 18, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 26, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 27, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue Apr 28, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue May 2, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this issue May 2, 2024
@maxonfjvipon maxonfjvipon reopened this May 2, 2024
@l3r8yJ
Copy link
Contributor

l3r8yJ commented May 10, 2024

@maxonfjvipon can you help a bit, did I understand correctly how this implementation works?

[cases] > switch
  cases.length > len!

  # Take case by given index.
  # If case key is true, return case value.
  # Otherwise take next case.
  [index] > case-at
    if. > @
      index.eq ^.len
      true
      if.
        at.
          ^.cases.at index > case
          0
        case.at 1
        ^.case-at
          index.plus 1
  if. > @
    len.eq 0
    error "switch cases are empty"
    case-at 0

Here we're got an objectswitch. switch decorates encapsulates an array of tuples, where each of them consists of 2 objects. First object – the condition, the second one – something that we have to return if condition was true.

I'm not sure that I can say what happens here cases.length > len!, but I can suppose that something like "alias" for our object – switch, and later we can get access to this value via ^.len.

Object case-at decorates encapsulates index of all tuples. If index equal to length of cases – returns true, otherwise execute next if. Next if object says that if case(i.e. tuple) has true at 0 index then we need to return tuple at 1, otherwise recursively return an object case-at with incremented index?

@maxonfjvipon
Copy link
Member Author

@l3r8yJ you're right. But switch does not "decorates" tuple of tuples, it "encapsulates" it. The same story with recursive case-at

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants