What does it depend on? 

On Thursday, April 17, 2025 at 12:48:26 AM UTC+3 Ben Noordhuis wrote:

> On Wed, Apr 16, 2025 at 8:21 PM GregRos <work....@gmail.com> wrote:
> >
> > I'm writing a low-level, CPU-bound parsing library, and I want to make 
> sure the parsing code is as efficient as possible.
> >
> > I know that V8 will sometimes inline function calls if they're "simple" 
> enough, don't contain any blacklisted syntax, etc.
> >
> > But will it do the same with instance method calls? For example, let's 
> say I just have a very simple wrapper like this:
> >
> > class X {
> > arr
> > constructor(arr) {
> > this.arr = arr
> > }
> >
> > push(x) {
> > this.arr.push(x)
> > }
> > }
> >
> > Would a call like `x.push(1)` get inlined into `x.arr.push(1)`?
> >
> > If so, what if I complicate things a bit:
> >
> > If `push` instead calls another instance method. Would both calls get 
> inlined?
> > If it's an inherited method up the prototype chain (but is never 
> overriden)
> > If push calls a function in a variable, like if it received a function 
> argument and called it. Would the body of push get inlined even if the 
> internal call cannot be inlined?
>
> Depends. Probably, but...
>
> The optimizing tiers are pretty good at inlining (it isn't called the
> mother of all optimizations for nothing) but JIT compilers are, by
> necessity, a bunch of heuristics and estimates, and they change all
> the time. What works today need not work tomorrow.
>
> In general, it's best to write your code in a straightforward manner
> and not worry too much about performance upfront. V8 generally does a
> lot better on mundane code than code that tries to be clever because
> the former is its bread and butter. Only start thinking about tuning
> when profiling shows hot spots.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/v8-users/05217515-f494-48a7-a182-951619eade0cn%40googlegroups.com.

Reply via email to