Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`stdLambda` performance re-visited

Abierto
#49 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Refactorización
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
visualbasic
Área
performance

Línea de trabajo

The issue provides a VBA benchmark comparing stdLambda with clsMathParser, but names no source files or tests. Start by reproducing the supplied benchmark and reading the stdLambda implementation and commit 2a9b2e0. Done is not defined; the issue suggests investigating a pre-populated stack and other performance differences without selecting a concrete change.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

lib-stdLambda megathread performance

stdLambda Performance

It has come to my attention that there exists another library a lot like stdLambda, named clsMathParser. This library apparently existed since 2004(?!), so totally unsure how this skipped passed my radar! It's not a very intuitive library but essentially functions as follows:

With new clsMathParser
  .storeExpression("x+1")
  For i = 1 to 100
    variable("x") = i
    Debug.Print .eval()
  next
End With

This library is, according to my testing, 5x vaster than stdLambda. Test set:

Sub test()
  Dim math As New clsMathParser
  Dim lambda As stdLambda: Set lambda = stdLambda.Create("$1^2+$1+2")
  
  If math.StoreExpression("x^2+x+2") Then
    With stdPerformance.Measure("clsMathParser", 10000)
      Dim i As Double, l As Double
      For i = 1 To 1000000
        math.variable("x") = i / 1000
        l = math.Eval()
      Next
    End With
    
    With stdPerformance.Measure("stdLambda", 10000)
      For i = 1 To 1000000
        l = lambda.Run(i / 1000)
      Next
    End With
  End If
End Sub

Comparrison of algorithm

  • clsMathParser's stack is pre-populated with values paired with operators. This ultimately means less operations done in VBA side:
    • clsMathParser splits x^2+x+2 into 3 operations:
      • ET(0) = completion op
      • ET(1) = ^ prevArg + varX^2 (???)
      • ET(2) = + prevArg + varX
      • ET(3) = + 0+2
    • stdLambda splits$1^2+$1+2 into 7 operations
      • ops(0) = Arg 1
      • ops(1) = Push 2
      • ops(2) = Op Pow
      • ops(3) = Arg 1
      • ops(4) = Op Add
      • ops(5) = Push 2
      • ops(6) = Op Add
      • ops(7) = Completion
  • stdLambda's starts with an empty stack and alocates it with values at runtime. Though we're only copying a few bytes I guess this consumes a lot of time compared to having all that data pre-prepared. A pre-populated stack is something we should likely look into.
  • stdLambda used to be copying argument location from a string at runtime, which is slow! I changed this and it saves some 30µs per operation. Fixed in 2a9b2e0
  • clsMathParser isn't stand alone sadly, and doesn't provide object access. stdLambda does provide object access and is standalone by comparrison (although technically requires stdICallable - easily removed by comparrison)
  • Cleverly clsMathParser uses a ByRef param for the return type. That shaves off some time, although not significant in my tests. But still clever fosho :)
Lenguaje dominante
VBA
Estrellas
412
Forks
70
Merge medio
16 h 10 min
PR fusionados (30 d)
3

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sancarn/stdVBA

Todos los issues de sancarn/stdVBA

Issues similares

Más issues de Performance

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.