Coder Social home page Coder Social logo

Comments (2)

yjunechoe avatar yjunechoe commented on June 10, 2024 1

I realize that I've made this issue more complicated than needed, and performance wasn't the right framing for understanding the problem. Closing in favor of #509

from pointblank.

yjunechoe avatar yjunechoe commented on June 10, 2024

Actually, the performance problem scales with the size of the data frame too (so you can ignore the convoluted reprex above). This is because hashing the (in most cases, global) environment will often also hash the table (and everything else) that's also available in the environment.

With that in mind, a newer, more minimal reprex on a 1-million row dataframe (using CRAN version this time, but the problem also exists on dev):

library(pointblank)
big_table <- small_table[sample(nrow(small_table), 1e6, replace = TRUE),]
agent <- create_agent(big_table)

profvis::profvis({
  agent %>% 
    col_vals_gt(
      columns = c("c", "d", "e"),
      value = vars(a),
      preconditions = . %>% 
        dplyr::select(a, c, d, e)
    )
})

image

The slowdown is specifically being driven by hashing the vars() quosure (sha1.formula()) and the preconditions function (sha1.function()). Both methods hash the attached environment by default:

image

And of course, the problem also scales with the number of validation steps added to the agent:

system.time({
  agent %>% 
    col_vals_gt(
      columns = c,
      value = vars(a),
      preconditions = . %>% 
        dplyr::select(a, c)
    ) %>% 
    col_vals_gt(
      columns = d,
      value = vars(a),
      preconditions = . %>% 
        dplyr::select(a, d)
    ) %>% 
    col_vals_gt(
      columns = e,
      value = vars(a),
      preconditions = . %>% 
        dplyr::select(a, e)
    )
})
#> user  system elapsed 
#> 2.07    0.39    6.72

Resolving value and preconditions to string before hashing resolves the performance issue (I'm testing this on a local branch):

devtools::install_github("yjunechoe/pointblank@no_env_hash")
library(pointblank)

big_table <- small_table[sample(nrow(small_table), 1e6, replace = TRUE),]
agent <- create_agent(big_table)

system.time({
  agent %>% 
    col_vals_gt(
      columns = c,
      value = vars(a),
      preconditions = . %>% 
        dplyr::select(a, c)
    ) %>% 
    col_vals_gt(
      columns = d,
      value = vars(a),
      preconditions = . %>% 
        dplyr::select(a, d)
    ) %>% 
    col_vals_gt(
      columns = e,
      value = vars(a),
      preconditions = . %>% 
        dplyr::select(a, e)
    )
})
#> user  system elapsed 
#> 0.04    0.02    0.14

The "resolve to string before hashing" solution currently fails the multiagent tests (but passes all others) and it will break backwards compatibility as is. But since the multiagent has all the info that was used to generate the original hash, I wonder if we can (optionally) have the hash for each validation step be re-generated by the multiagent for the purposes of alignment (which I believe would still guarantee correct alignment for older agents)?

from pointblank.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.