Does v8 engine cache returned value from a function?

81 views
Skip to first unread message

Jeongho Nam

unread,
Dec 21, 2022, 4:07:20 AM12/21/22
to v8-users
Hello, I'm developer of typia and running a benchmark program about runtime validators. During the benchmark development, I've experience amazing happen that, if I repeat same function repeatedly with same parameter value, typia became relatively about 8x times faster than slowest (class-validator).

------------------------------------------

  - only one validation:  Benchmark, consider over-fitting optimization · Issue #427 · samchon/typia (github.com)

15,000x faster code, multiple validation
for (const elem of data) // length is 4 to 100
    typia.is<ObjectSimple>(elem);

200,000x faster code, only one validation
typia.is<ObjectSimple>(data);

------------------------------------------

After seeing such difference, I'm wonder whethering that v8 engine caches returned value from a function or not. I can't sure what is the reason why. Is it caused by costs of array iteration? Or caused caching optimization from v8 engine?

Anyone who can explain and teach me? Please inform me the reason.

Toon Verwaest

unread,
Dec 21, 2022, 6:10:12 AM12/21/22
to v8-u...@googlegroups.com
I'm not exactly sure what you're running, but I assume it's something like:

```
var global = some_object;
for (let i = 0; i < ....; i++) {
  do_something(global)
}
```

V8 will learn that "global" never changes, and will optimize the loop in which `do_something` will be inlined; specializing it on the "dynamic constant" global. it might go as far as eliminating all code in the loop and just running an empty loop for the remainder of the benchmark. Benchmarking is hard ;-)

--
--
v8-users mailing list
v8-u...@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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/6034f4a3-9d9b-4a1e-bc0b-11f51c26754an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages