Why not sending JavaScript files in browser-specific bytecode? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
There is no universal bytecode for JavaScript, but most JavaScript engines have their own bytecode. Since JavaScript files travel as source code string, they have to parse/compile source code string into bytecode at before execution.
However, as we can specify a user agent type (e.g. browser type and version) in HTTP request, can't we make the server keep bytecode for each browser and respond accordingly to save some time at client?
What's preventing us from taking this approach? I don't think browsers will have no problem even if some JavaScript files are given in bytecode and others in source string. Similarly, we have .pyc files in Python, and it runs well with .py files.
[Update]
Potential benefits I can think of are below.
You could save parsing time at client. Parsing is fast, but it may be worth to do it for low-end devices.
You could put some hints in bytecode. For example, JavaScriptCore (WebKit's JavaScript engine, JSC for short) patches bytecode with information gathered during runtime, such as types. JSC's bytecode is designed in a way that it has slots for such information.
In terms of maintainability, the server can always send the original source code string if the client's browser is unsupported, and there are not so many different JavaScript engines. Supporting four most popular browsers (Chrome, Firefox, IE and Safari) seems feasible to me. In addition, I don't see bytecode instruction set changing frequently.

All engines would need to make their byte code format public
The server would need to hold very many different byte code files, or even compile them on the fly
Browser detection is fraught with peril (user agents lie, proxies cache)
Bytecode rules might change between minor versions of a browser
The performance gains probably wouldn't be all that significant (especially when compared to network transfer times)

Related

Can one create an OS using JS or PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
This is a question of interest, There are a number of interpreted languages that can be used to create an OS, Can one create an Operating system using PHP or JS.
It does not have to be a fully-fledged OS, at least the one that prints Hello World.
Regards
All three of those languages are Turing-complete, so they can simulate any other Turing-complete language. An operating system written in one (or a few) Turing-complete language can also be written in another, assuming that sufficient access to the underlying hardware is provided.
Whether such a thing could be made to be run any any reasonable speed is another matter entirely.
The number of things you can do in programming is virtually limitless, but many of those things require a lot of effort.
The main purpose of an operating system is to provide an interface between application programs and the computer hardware, often abstracting away details. In order to do this, the OS code must be able to access the hardware directly (or almost directly, e.g. by calling BIOS functions).
High-level languages like PHP and JavaScript don't have any mechanisms to do this. They depend on an operating system to provide access to hardware at a high level: files, network sockets, etc.
These languages do allow you to link in extension libraries, which give them extra capabilities. But then you're not actually writing the OS in these languages, you're writing it in the language that the extension is written in.
I don't think even C can be used to write an OS if you just stick to the portable features of the language. Operating systems written in C depend on implementation-dependent features such as casting integers to pointers, they use extensions like asm(), or they occasionally link with subroutines written in assembly, on order to get direct control of the hardware.

Is there a performance benefit to shipping Web Assembly vs minified Javascript? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Is there a performance benefit from serving Javascript compiled to Web Assembly (perhaps by AssemblyScript?), vs minified Javascript?
I'm specifically thinking about:
parse / compile time
execution time
byte size
memory usage
how CDNs interact with it (serving binary application/wasm vs text application/javascript)
parse / compile time
Well it's already compiled, that's the whole point of WASM. If you mean from ByteCode to Nativecode, this should be much faster than from Javascript to Native code.
execution time
Yes, faster, again it's kind of the whole point.
byte size
Debatable here, I think minified Javascript is pretty efficient here.
memory usage
WebAsembly is meant to compliment Javascript, so in theory it's the same,..
how CDNs interact with it (serving binary application/wasm vs text application/javascript)
A CDN it's just a place to ship assets, so I can't see this been an issue. eg. Fonts and images are binary, and they work fine. BTW, wasm comes with the same security policy's as Javascript, so it's not like shipping an EXE over the wire.

Why are modern browser JS engines multi-threaded? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I understand modern browsers' JS engnines (like V8, Spidermonkey, Chakra, etc.) use thread pools internally, even though only a single thread (running the event loop) is exposed to a JS programmer.
Obviously, the (rarely used) Web Workers require multiple threads (or multiple processes) - otherwise they couldn't utilize multiple CPU cores. My question is, apart from Web Workers, what is the benefit of implementing JS engine with multiple threads?
Why couldn't JS engine remain always single-threaded by internally relying on the same event-loop that the JS programmers use, using non-blocking OS calls whenever it needs to do any IO?
To clarify: JS engine uses a thread pool even if the user opened just one window with just one tab.
Edit: this is answered here
There are many parts of a script engine that benefit from parallelisation, as they can run concurrently for different parts of the script or in relation to each other:
parsing
compilation
JIT, optimisation
debugging/logging/profiling
garbage collection
graphics
And that doesn't even involve sharing between multiple instances of the engine for different usage environments (worker scripts, browsing contexts).

which one is the fastest? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a website which is used on Chrome and IE8. I made it with Javascript and it works fine on Chrome but it is slow on IE.
Is VBScript faster than Javascript on IE? Would I translate my code in VBScript for IE?
VBScript is executed for web sites on IIS(web servers), JavaScript mostly on client side.
I do not see how it would not work on any browsers unless you uploading something to client machines as vbs file. That is dangerous and could be considered as security threat - antivirus program may simply block it or delete file all together.
Basically question is not about if VBScript supported or not by any browsers simply because browsers never-ever touching VBScript, but what you attempt to do with VBScript. And anyone who is saying that it does not supported by any browser need to take a lessons from W3S school all over again.
It is different purpose scripting languages on the web: VBScript for servers side processing while JavaScript mostly to be used running on client side. And before anyone starts discussing that JavaScript can be used on server side please look what I put in bold letters. There are javascript libraries AJAX and JQUERY etc. which can be used to process data as well as connecting to web servers.
If you are looking for replacement of VBScript - C# is the best place to start since you already working on Microsoft platform, NET would be logical choice. There is lot of other languages to choose from but you need carefully consider what your project is all about, budget and time needed to rebuild your project/site.
However you can write VBScript and JavaScript batch files for local execution but as I understand that is not part of your question.

Am I allowed to run a javascript runtime (like v8) on the iPhone? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
According to this discussion, the iphone agreement says that it doesn't allow "loading of plugins or running interpreted code that has been downloaded".
Technically, I would like to download scripts from our server (embedded in a proprietary protocol).
Does this mean I wouldn't be allowed to run a runtime like v8 in an iphone app?
This is probably more of a legal question.
I think your interpretation is correct - You would not be allowed to download and execute JavaScript code in v8.
If there were some way to run the code in an interpreter already on the iPhone (i.e. the javascript engine in MobileSafari) then that would be permitted I think.
This is partially a technical question too. V8 as currently implemented won't run on the iPhone. No JIT-based VM will.
Well I embedded Lua into my application already and am programming most of the login in Lua and then downloading it to my iPhone for fast iteration, but this is only intended during development. Once I ship the scripts will be placed in the source and compiled into byte-code shipped along with the app just like any other resource.
I'd say this applies to V8 aswell.
I concur. My reading is also that DOWNLOADED scripts are not allowed. Pre-installed and user-written scripts are fine. But it is a fine distinction and IANAL etc etc.

Categories

Resources