Replace validation visitor stacks with single-slot variables#5587
Replace validation visitor stacks with single-slot variables#5587swalkinshaw wants to merge 1 commit intomasterfrom
Conversation
| @field_definitions = [] | ||
| @argument_definitions = [] | ||
| @directive_definitions = [] | ||
| @path = Array.new(32) # pre-allocated, indexed by @path_depth |
There was a problem hiding this comment.
This is interesting: IIUC, instead of dynamically growing and shrinking the Array, we're using a big array with the expectation that only the first @path_depth items are correct. Instead of appending a new item to @path, call sites assign a value in @path at the current @path_depth then increment @path_depth.
Just curious, is there any reason for 32 in particular?
There was a problem hiding this comment.
I think in isolation this had a tiny improvement but in the context of removing the push/pop operations already I think going back to [] is just simpler. Ruby doubles the array size as it grows so really this might avoid like 3-4 resizes (a realloc + memcpy of a few pointers?) which is nothing. Plus for small queries it's over allocating technically.
Removed!
There was a problem hiding this comment.
I definitely didn't mean to argue against starting at 32 slots, I was just genuinely curious why 32. I thought I might learn some Ruby secrets! Either way is fine for me.
Eliminates array push/pop operations per validation pass by replacing array-based stacks with single-slot variables that use the Ruby call stack for save/restore. Pre-allocates path array indexed by depth counter.
befea5a to
91de7fd
Compare
Extracted #5578
Eliminates array push/pop operations per validation pass by replacing array-based stacks with single-slot variables that use the Ruby call stack for save/restore. Pre-allocates path array indexed by depth counter.
In our schema, this saves about ~5500 push/pop operations and resulted in a 5-6% perf improvement.
I'll defer to you if you think this makes the code more complex and harder to manage but I think it's about the same.