Hint V8?

127 views
Skip to first unread message

Egor Egorov

unread,
Dec 16, 2011, 6:23:40 AM12/16/11
to v8-u...@googlegroups.com
Let's suppose I have a function that expects an argument of a certain type, a number. 

What if I somehow hint the V8 compiler that here I expect only a number so that V8 optimises accordingly without guesses? Would such a hint make sense for V8 optimisation process? 

Vyacheslav Egorov

unread,
Dec 16, 2011, 6:51:23 AM12/16/11
to v8-u...@googlegroups.com
You can't hit it explicitly.

But V8's optimizing compiler gathers type feedback from inlined caches in the non-optimized code. 

Essentially this means that program itself gives hints to V8 while it executes, e.g. if you write function like

function add(x, y) { return x + y; }

and you will call it with numbers only V8 will in the end generate code that is specialized appropriately for the number case.

--
Vyacheslav Egorov

On Fri, Dec 16, 2011 at 12:23 PM, Egor Egorov <egor....@gmail.com> wrote:
Let's suppose I have a function that expects an argument of a certain type, a number. 

What if I somehow hint the V8 compiler that here I expect only a number so that V8 optimises accordingly without guesses? Would such a hint make sense for V8 optimisation process? 


Egor Egorov

unread,
Dec 16, 2011, 3:11:01 PM12/16/11
to v8-u...@googlegroups.com

Yes but how many calls do I have to fire till this optimisation takes place? 

On Friday, December 16, 2011 1:51:23 PM UTC+2, Vyacheslav Egorov wrote:
[]

Vyacheslav Egorov

unread,
Dec 16, 2011, 5:35:31 PM12/16/11
to v8-u...@googlegroups.com
It will be optimized when V8 decides that it's hot. (or maybe when V8 inlines it into some other function, etc). "Hotness" is estimated based on many factors, e.g. statistical profiling. You can use --trace-opt to see functions that are being optimized by V8.

Why do you want to ensure that this function is optimized? If it is frequently called and it takes non-trivial amount of time to execute --- it will be optimized.

--
Vyacheslav Egorov

--

Egor Egorov

unread,
Dec 17, 2011, 1:46:20 PM12/17/11
to v8-u...@googlegroups.com

Thanks for explanations. 

Just looking for a way to speed up my CPU-intensive application. It takes about 20 minutes to run on the top high-cpu amazon EC2 instance; yes, it is a multi-procees application:) 

Reply all
Reply to author
Forward
0 new messages