HN user

dnadolny

70 karma
Posts2
Comments23
View on HN

> I don't know how JVM bytecode works, or if it's even possible to assign discontiguous ordinal values

That was my first thought as well, but I double checked and the ordinal() method is final, so you're guaranteed not to get anything other than continuous values for your enums.

> in C compiled to x86 assembly language, a switch statement on (mostly-)contiguous values can be converted into a jump table

Ah, this is probably the intention. The JVM can probably optimize the switch. I just checked it, and when there are multiple switch statements in a class only using a few values in an enum, it tries to make them all sequential in the switch, that's why it uses the array. I guess it's just a mistake (or lazy coding) that it always makes the array size TheEnum.values().length rather than how many it's actually going to use.

The .equals() still shouldn't be much of a problem. If you've got a bunch of constants like you gave, they will probably all have different hashcodes so you don't have to compare against all of them.

I checked what happens when you use an enum, and it generates some funky code. It creates an anonymous inner class with a static initializer for an array of ints. It uses the ordinal value to assign a sequential number starting with one. Then the switch statement is on intArray[theEnum.ordinal()], and the case statements start with 1. Here's the code:

  class Test2{
    public static void main(String[] args) {
      MyEnum en = MyEnum.ONE;
      switch (en) {
        case ONE:
          System.out.println("one"); break;
        case TWO:
          System.out.println("two"); break;
        default:
          System.out.println("default");
       }
    }
  }

  enum MyEnum {
    ONE, TWO, THREE;
  }
Decompiled (after being compiled with jdk1.7.0):
    public static void main(String args[])
    {
        MyEnum myenum = MyEnum.ONE;
        static class _cls1
        {

            static final int $SwitchMap$MyEnum[];

            static
            {
                $SwitchMap$MyEnum = new int[MyEnum.values().length];
                try
                {
                    $SwitchMap$MyEnum[MyEnum.ONE.ordinal()] = 1;
                }
                catch(NoSuchFieldError nosuchfielderror) { }
                try
                {
                    $SwitchMap$MyEnum[MyEnum.TWO.ordinal()] = 2;
                }
                catch(NoSuchFieldError nosuchfielderror1) { }
            }
        }

        switch(_cls1.$SwitchMap$MyEnum[myenum.ordinal()])
        {
        case 1: // '\001'
            System.out.println("one");
            break;

        case 2: // '\002'
            System.out.println("two");
            break;

        default:
            System.out.println("default");
            break;
        }
    }
I wonder why it doesn't just switch on the ordinal directly. It's also worth noting that it has to make an array for MyEnum.values().length. This means if you have an enum with a lot of values, you're wasting a lot of memory (especially since it creates this array every class you use a switch in). I tried with an enum with 40 values, and it didn't switch to a map. Maybe there's some higher threshold where it would switch to a map instead (but again, I don't understand why it wouldn't switch on ordinal() directly).

> And one that I can't get confirmation on if it's in 7 or got pushed, index-access for List and Maps

I just tried it out, it didn't get added to 7.

> String-in-switch (NOTE: check on performance implications of this for tight loops)

I haven't checked the performance, but I tried decompiling a String switch statement:

  String test = "asdf";
  switch (test) {
    case "sss":
      System.out.println("sss");
      break;
    case "asdf":
      System.out.println("asdf");
      break;
  }
That decompiles to:
  switch(test.hashCode()) {
    case 114195:
      if(test.equals("sss"))
        byte0 = 0;
      break;
    case 3003444:
      if(test.equals("asdf"))
      byte0 = 1;
      break;
  }
  switch(byte0) {
    case 0: // '\0'
      System.out.println("sss");
      break;
    case 1: // '\001'
      System.out.println("asdf");
      break;
  }
So it's one switch on the String's hashcode, with calls to equals to verify that the string is a match (and an if/else if/else block if you have multiple strings in the switch that have the same hashcode), assigning the result to a temp variable, and then a switch on a temp variable to execute your code.

It looks like it would be fairly quick.

I disagree with recruitment not adding value. Imagine a recruiter that sent you 5 qualified candidates who were all interested in your job. You would spend a little bit of time in the interview to verify they were qualified, but mainly you just have to decide who is the best fit for your team. Compare that to hours of reviewing resumes, tens of hours of interviews on unqualified candidates, etc.

A recruiter could offer a lot of value, the problem is that it's difficult to show that you're a useful recruiter. This is an econ problem[1], where you have people offering something valuable and people offering something not very valuable and you can't tell the difference. What's needed is a way of signaling that they're going to be a good recruiter.

[1] http://en.wikipedia.org/wiki/The_Market_for_Lemons

It's a technicality. You always get a copy of what you pass in. When you pass a primitive, eg an int that has the value 7, you get a copy of that value 7. When you pass an object, you get a copy of the reference to that object.

You understood correctly, it's just how it gets phrased.

We really think alike - the captcha idea, and the URL shortener with a miner at the top were two of my first ideas for uses of an API.

I didn't think of marketing it to internet cafes/kiosks though.

No need to apologize for how you feel - some people love the idea (of supporting a website with their computer power), some people hate it.

As for the resource overhead of the JVM, it's infeasible to have a bitcoin miner that uses javascript - that was how I did it initially, as a proof of concept, but it was so slow I abandoned it.

Yeah, I'd really like to use the GPU, it would be a huge speed boost.

Was it lagging when you were scrolling down? I try to play nice with the CPU and run it at low priority, so it shouldn't interfere. What OS/browser/java version combo has trouble?

This one isn't javascript, it's based on my browser bitcoin miner[1] which is written in Java. It's about 2000 times faster than the javascript bitcoin miner that I know of.

It's around 30-40% slower than one of the optimized C CPU miners, and of course it's a a lot slower than a GPU miner, but it mines at a reasonable rate (and it starts up quickly)

As for effective monetization, this is something you can run in addition to regular ads if you wanted, since it doesn't take up any screen space.

[1] http://www.bitcoinplus.com/generate

I've made an option to add controls, which shows the current hashrate and a start/stop button. Right now it's up to the websites using it to enable that if they want to.

I like the captcha idea, I've actually been planning something like that. I've got some changes I need to make to my infrastructure before I can do that, but I'm hoping to do it (or let other people do it with the API I'm going to offer).

Thanks for the advice about making the user feel appreciated, I think that's quite important.

Can I ask why?

The way I see it, websites with advertisements use your mind (by grabbing your attention). This only uses your computer. Which would you rather have a website try to take over?

I'm sure any embeddable bitcoin miner will be added to adblock pretty quickly, so you won't have to worry.

Would it change your mind if you were given a portion of the bitcoins generated while you were on a site that was doing this?

I get where you're coming from. Here's an interesting thought: consider this as an alternative to advertising.

Which would you rather: a website use your mind by taking your attention to an advertisement, or a website using your CPU?

I'm curious, is your computer usable while you're using your GPU for mining? Or do you have a 2nd graphics card dedicated to mining?

I tried out GPU mining but my computer was unusable while it was running.

True.

I've been thinking this over for a while. Right now, the general consensus is that the price of bitcoin will end up being related to the cost of electricity for computing, and in the long run transaction fees will have to go up or down to make that happen.

I think this will change.

When you have negative externalities like this, where people don't pay for electricity (they're renting, or in a condo/apartment building that has electricity included) or even free CPU power, as in an office, then the economics change. The price of bitcoin won't be tied to the price of electricity/CPU power, it will be tied to the cost of running a website like mine that lets people take advantage of free CPU power.

Yes, it is slower than GPU mining. I meant this to be more of an introductory easy to use miner to get people interested without having to download anything or configure anything. So it is slower than GPU, but you can generate a usable amount of BTC to play around with

I wonder, what's the math behind the electricity use of an idle CPU vs a CPU at 100%?

That came up on the bitcoin forums (http://forum.bitcoin.org/index.php?topic=8780.0). I've got plans for doing something like that - let you embed the miner in your website so your visitors mine bitcoin for you. It's a really cool idea because you get money based on how long people stay on your page, rather than how many pageviews or click-throughs you have. Instead it's based on a more accurate measure of user interest - time spent on the page.

If anyone's interested in that, leave a reply here, or email me at donny@bitcoinplus.com and I'll let you know when it's ready.

That's correct, you can log in to as many computers as you want, all with the same account and it will work. You could even run multiple on the same computer and it would work perfectly - but of course it wouldn't make it any faster.

Yep, GPUs are much faster than CPUs for mining. A top of the line GPU does 600 MHash/sec, on my graphics card it was doing I think 3 or 4 MHash/sec but the computer was unusably slow, and with a CPU miner I get 2 MHash/sec and my computer is perfectly usable. This is targeting the people who are interested in bitcoin (you can still mine a usable amount), but don't want to set up a dedicated mining machine.

Right now it doesn't use the GPU but I've got plans to do it too (it might be able to work with the new OpenCL stuff that's going on)

I've just finished a browser-based bitcoin miner, written in Java (as an applet).

I'd love to get some feedback on it.

Once the page loads, hit "Start generating" and it should start mining bitcoin.

I find it a bit funny he says you won't be able to borrow against it, but went on to refute that saying several of his friends made offers to lend him the money.

Having a solid network of friends and contacts does have quantifiable effects.