## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE ) ## ----------------------------------------------------------------------------- # p <- profvis({ # tmp <- tidypredict_fit(rf_tree) # }) # # pv_print_debrief(p) ## ----------------------------------------------------------------------------- # # Before (O(n) per lookup): # row <- tree[tree$nodeID == j, ] # lc <- row["leftChild"][[1]] == find # # # After (O(1) per lookup): # idx <- j + 1L # lc <- left_child[idx] == find ## ----------------------------------------------------------------------------- # # Before: Linear search for parent # for (j in node_id:0) { # idx <- j + 1L # lc <- left_child[idx] == find # lr <- right_child[idx] == find # if (is.na(lc)) lc <- FALSE # if (is.na(lr)) lr <- FALSE # if (lc || lr) { ... } # } # # # After: Direct traversal using parent lookup # while (!is.na(parent[current + 1L])) { # current <- parent[current + 1L] # path <- c(path, current) # } ## ----------------------------------------------------------------------------- # # Before: # if (.x$op == "more") i <- expr(!!sym(.x$col) > !!.x$val) # if (.x$op == "more-equal") i <- expr(!!sym(.x$col) >= !!.x$val) # if (.x$op == "less") i <- expr(!!sym(.x$col) < !!.x$val) # if (.x$op == "less-equal") i <- expr(!!sym(.x$col) <= !!.x$val) # # # After: # switch( # .x$op, # "more" = expr(!!col_sym > !!val), # "more-equal" = expr(!!col_sym >= !!val), # "less" = expr(!!col_sym < !!val), # "less-equal" = expr(!!col_sym <= !!val) # )