473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using AJAX/JSON and performance issues with eval()

Hi,

Im currently looking to move into using JSON for AJAX instead of
returning from the server a string like the following:

12345{This is a text string{true[1234|This is another set of fields|
null

This is returned from the server and I use split() and loops to
generate JS arrays / nested arrays at the client end. I cannot use XML
is it is deemed to heavy for the website as we deal with very high
volumes of traffic and trying to reduce the data sent back and forth
through the client and servers. The problem with the above is that it
makes my life as a JS programmer harder coz I have to do all this
splitting and looping to seperate the data

Now JSON seems the perfect on both fronts - it is lightweight and I
only have to use a single eval() to replace what splits() and loops
done previously. I can also have as many levels and nesting as I wish.
There are a couple of conserns I have here tho:

Eval() I have heard can be quite slow? Is this a serious concern for
large data sets? Even if it is slow, is it still going to be faster
than my previous method above?

I understand that you can have a JSON format for JS arrays and JS
objects:

// array
{0: 12345,2:"This is a text string"}

// object
[12345,"This is a text string"]

I prefer objects because I dont need to specifiy the index key and I
can treat it exactly like an array - oSet[0] = ...
Are objects just as quick to access/alter as arrays? I have a few
simultaneous client processes going on (ie. refreshing multiple HTML
tables automatically in the background) and really want it to perform
well.
Is there anything else worth considering when using JSON? My website
is mainly just updating content on multiple tables and refreshing data
every so often, thats about the extent of it.

Thanks

Burnsy
Jul 1 '08 #1
1 2659
bizt wrote:
Im currently looking to move into using JSON for AJAX instead of
returning from the server a string like the following:

12345{This is a text string{true[1234|This is another set of fields| null

[...] The problem with the above is that it makes my life as a JS
programmer harder coz I have to do all this splitting and looping to
seperate the data

Now JSON seems the perfect on both fronts - it is lightweight and I only
have to use a single eval() to replace what splits() and loops done
previously. I can also have as many levels and nesting as I wish. There
are a couple of conserns I have here tho:

Eval() I have heard can be quite slow? Is this a serious concern for
large data sets?
I don't think so.
Even if it is slow, is it still going to be faster than my previous
method above?
Probably yes. eval() evaluates its string argument as an ECMAScript
Program. This evaluation is implemented in native, already compiled (with
few exceptions platform-dependent) code. That should be considerably faster
to execute than your implementation, which needs to be JIT-compiled and the
resulting byte-code interpreted by a VM first.
I understand that you can have a JSON format for JS arrays and JS
objects:
Just to add to confusion: JS arrays are implemented as objects, Array
objects. What you call "JS objects" here, are (augmented) Object objects.
// array
{0: 12345,2:"This is a text string"}

// object
[12345,"This is a text string"]

I prefer objects because I dont need to specifiy the index key and I can
treat it exactly like an array - oSet[0] = ...
The above is the reason for that. `0' is the name of either object's
property, only that the method of property access with Array objects differs
slightly from that of other objects.
Are objects just as quick to access/alter as arrays?
I think they are quicker to alter than arrays when it comes to inserting
items, and just as quick when accessing items. To be sure, you could do an
estimation of general runtime efficiency on the corresponding algorithms in
the ECMAScript Specification, Edition 3 Final, and compare with empirical
results for different input.
I have a few simultaneous client processes going on (ie. refreshing
multiple HTML tables automatically in the background) and really want it
to perform well.

Is there anything else worth considering when using JSON? My website is
mainly just updating content on multiple tables and refreshing data every
so often, thats about the extent of it.
When dealing with tables, you should consider a combination of both:

[
{x: 42, z: 23},
{x: 1337, z: 1701}
]
PointedEars

P.S.
Please don't use off-Usenetter slang like "coz" here. Besides presenting
you as a semi-literate, this is an international newsgroup.
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Jul 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
1
by: Andrew Poulos | last post by:
There's an object: foo = new Object(); and a property called 'bar' with a value of 1 is to be added to it using JSON. If I try the following it only demonstrates my ignorance: var str =...
0
by: John Dufour | last post by:
AJAX Consultant Top NY newspaper is seeking a candidate who is confident about building and extending a personalization platform for xxxx.com, a site with an unparalleled combination of scale...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
1
by: Andrew Burton | last post by:
I'm poking at a small "single page application" (SPA), ala TiddlyWiki, to act as kind of a local, single-user version of Twitter (no real application, except to familiarize myself with JavaScript)....
13
by: My Pet Programmer | last post by:
The way I usually set up and work with the XMLHttpRequest to execute server side functions and get results is this: var url = "someurl?params=" + params; var conn = createRequest(); // gets an...
8
by: Rory Becker | last post by:
Hi All I have a need for an asp.net page to make a call to a server which it did not originate from when a button is clicked. A simple call to pass 2-3 params and return a result. I am happy...
5
dmjpro
by: dmjpro | last post by:
Recently I came to know that ..... it's better to to generate some JSON instead of plain HTML when i am calling AJAX. But today i read that the usage of eval is dangerous while i processing the AJAX...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.